Quick note

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...

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.

Joel Abrahamsson

Joel Abrahamsson

I'm a passionate web developer and systems architect living in Stockholm, Sweden. I work as CTO for a large media site and enjoy developing with all technologies, especially .NET, Node.js, and ElasticSearch. Read more

More about EPiServer CMS