Quantcast
Channel: Joel Abrahamsson
Viewing all articles
Browse latest Browse all 78

Add UIHint to an EPiServer property without affecting its editor

$
0
0

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.


Viewing all articles
Browse latest Browse all 78

Latest Images

Trending Articles



Latest Images