Code sample
RenderContentData with support for rendering tag
EPiServer 7 CMS' API features two HTML helper extensions for rendering partial content with MVC, both named RenderContentData. None of them offer a way to render content using a rendering tag.
The below extension adds such a method:
using System.Web.Mvc; using EPiServer; using EPiServer.Core; using EPiServer.Framework.Web; using EPiServer.ServiceLocation; using EPiServer.Web; using EPiServer.Web.Mvc; using EPiServer.Web.Mvc.Html; namespace MySite { public static class HtmlHelpers { public static void RenderContentData( this HtmlHelper html, IContentData content, string tag, isInContentArea = false) { var templateResolver = ServiceLocator.Current.GetInstance<TemplateResolver>(); var templateModel = templateResolver.Resolve( html.ViewContext.HttpContext, content.GetOriginalType(), content, TemplateTypeCategories.MvcPartial, tag); var contentRenderer = ServiceLocator.Current.GetInstance<IContentRenderer>(); html.RenderContentData( content, isInContentArea, templateModel, contentRenderer); } } }
Similar articles
- Custom rendering of content areas
- EPiServer editing delight challenge - MVC solution
- Custom routing for EPiServer content
- How EPiServer's HTML helper PropertyFor works
- EPiServer 7 and MVC – Custom tags and CSS classes when rendering properties
- EPiServer editing delight challenge - Web Forms solution
- EPiServer 7 and MVC – How to customize rendering of properties
- Limiting content and page reference properties to values of a specific type in EPiServer CMS