Try our conversational search powered by Generative AI!

Customize rendering of XForm in MVC Razor



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.

Feb 22, 2013 14:21

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

 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;
Edited, Mar 01, 2013 10:36


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.


Per Gunsarfs

Mar 01, 2013 13:38

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.

Mar 01, 2013 13:56

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.


Per Gunsarfs

Mar 01, 2013 15:58

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

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.