Try our conversational search powered by Generative AI!

Customize rendering of XForm in MVC Razor

Vote:
 

Hi,

I'm currently looking into customizing the rendering of XForms in MVC Razor (Getting rid of the table etc.), but not able to find much information on this topic. Does anyone have any information on how to accomplish this, or point me in the right direction ?

Thank you.

#66194
Feb 22, 2013 14:21
Vote:
 

We had an idea about this and came with the idea to create an extension of our own for HtmlHelper like the following:


public
 static class XFormsExtensions     {         public static MvcHtmlString ExtendedDisplayFor<TModel, TValue>(this HtmlHelper<TModel> html,                                                                        Expression<Func<TModel, TValue>> expression)         {             if (!(typeof(TValue)==typeof(XForm)))                 throw new ArgumentException("Can only be used on XForm");             var mvcHtml = html.DisplayFor(expression);             var content = mvcHtml.ToString();             return new MvcHtmlString(content.XFormToDivTransform());         }         public static string XFormToDivTransform(this string content)         {        // Do your transformation of choice here

return content;
}
#66476
Edited, Mar 01, 2013 10:36
Vote:
 

Hi

If I remember correctly the rendering of XForms in MVC is controlled by a set of editor templates. There should be one for each type of XForm fragment. The default ones can be found in the program files installation. The views are located under CMS\{versionNumber}\Application\Util\Views\Shared\EditorTemplates.

It should be possible to add overrides of those by placing custom views in the site folder ({siteRoot}\\Views\Shared\EditorTemplates). Those should have priority of the ones in program files.

Regards

Per Gunsarfs

#66490
Mar 01, 2013 13:38
Vote:
 

But aren't those templates for each element in a XForm and not the XForm as a whole? What we wanted to do was to get rid of the table-elements that holds the form-elements, which the templates Per speaks of seems to render.

#66494
Mar 01, 2013 13:56
Vote:
 

Ah, sorry misunderstood the original question. You are correct, those are only for the individual elements. For the wrapping thing you can use the approach that you suggested.

Regards

Per Gunsarfs

#66501
Mar 01, 2013 15:58
Vote:
 

Thanks Mathias. Looks like a good solution which I'll look into.

#66538
Mar 04, 2013 14:44
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.