Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anchor tag in form label using Html.LabelFor in MVC3

I would like to accomplish something like

<label for="AgreedToTherms">
I agree to the <a href="therms-and-conditions">Therms and conditions</a>
</label>

Is this allowed according to html standards? Using the standard Html helper in a view

@Html.LabelFor(model => model.AgreedToTherms)

I tried to use add the html inside the labeltext but this text gets html encoded

like image 870
jhoefnagels Avatar asked Mar 15 '12 13:03

jhoefnagels


1 Answers

You can do this way:

@MvcHtmlString.Create(HttpUtility.HtmlDecode(
    Html.LabelFor(m=>m.AgreedToTherms).ToString()))

(OR)

@Html.Raw(@HttpUtility.HtmlDecode(
    Html.LabelFor(m=>m.AgreedToTherms).ToString()))
like image 145
Min Min Avatar answered Nov 09 '22 19:11

Min Min