DisplayName text via LabelFor without encoding

Is there an elegant way to output text to the DisplayName attribute of a model property using LabelFor without coding? The DisplayName attribute contains an em tag, which should be displayed as raw HTML.

I would like to avoid creating a custom helper unless it's unavoidable. If unavoidable, please describe how to create a helper that can override LabelFor.

Property in the model:

[DisplayName("Title <em>&lt;title&gt;</em>")]
public string Title { get; set; }

      

Shaver type:

@Html.LabelFor(model => model.Title, new {@class = "control-label col-md-2"}

      

Output:

enter image description here

+3


source to share


1 answer


Sorry, but there seems to be no way to do this as shown in this helper source code post:

Adding html covers in LabelFor-MVC 3



It looks like you should implement your helper.

+1


source







All Articles