Add UIHint to an EPiServer property without affecting its editor
We can use UI hints to make the PropertyFor and DisplayFor methods use a specific display template when rendering properties with ASP.NET MVC.
For instance, when rendering a property like this...
[UIHint("Banana")]
public virtual string Heading { get; set; }
...using Html.PropertyFor() it will be "sent" to a display template named Banana, given such a template exists.
There's just one problem. When adding a UI hint that no editor descriptor cares about we loose the original editing functionality for the property and it will be edited using the "legacy" editing functionality. That is, instead of a textbox for a string property editors will see a button saying "Click the button to edit".
To fix that, use an overload for the UIHint attribute and specify PresentationLayer.Website, like this:
[UIHint("Banana", PresentationLayer.Website)]
public virtual string Heading { get; set; }
One caveat, while this works great with PropertyFor it won't work with DisplayFor which won't recognize the UI hint any longer.
Similar articles
- EPiServer editing delight challenge - MVC solution
- How EPiServer's HTML helper PropertyFor works
- Custom rendering of content areas
- EPiServer editing delight challenge - Web Forms solution
- Display template for images when using EPiServer CMS and ASP.NET MVC
- Limiting content and page reference properties to values of a specific type in EPiServer CMS
- EPiServer 7 – Content, Pages and Blocks
- EPiServer 7 and MVC – How to customize rendering of properties