craigmoliver
craigmoliver

Reputation: 6562

DisplayName text via LabelFor without encoding

Is there an elegant way to output the text in a model property's DisplayName attribute using LabelFor without encoding? The DisplayName attribute contains an em tag that need to rendered as raw HTML.

I'd like to avoid creating a custom helper unless it is unavoidable. If it's 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; }

Razor view:

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

Output:

enter image description here

Upvotes: 3

Views: 776

Answers (1)

Tobias
Tobias

Reputation: 2985

Sorry, but it seems there is no way of doing this like this post with original helper source code is showing:

Adding html spans into a LabelFor - MVC 3

Seems like you have to implement your own helper.

Upvotes: 1

Related Questions