I need to render a HTML link that exists inside of a resource file

[Display(Name = "MyPropertyName" ResourceType = typeof(Res.Props))]
public bool MyProperty{ get; set; }

The MyPropertyName resource has some HTML:

"Click <a href="bla.com">here</a> to find out more."

I need to render this on the View so the link is clickable. The HTML will never render despite what method I attempt, some attempts (not exact syntax but you get the gist) will display the raw HTML, and some don't display anything at all.

var htmlLabel = Html.LabelFor(m => m."MyPropertyName" ).ToString()
Html.Raw(htmlLabel)

Html.Raw(Html.LabelFor(m => m."MyPropertyName" ).ToString())
Html.Raw(Html.LabelFor(m => m."MyPropertyName")

MvcHtmlString.Create(htmlLabel);
Html.Raw(MvcHtmlString.Create(htmlLabel))

etc.

I found a suggestion of getting the attribute info on the controller and passing it in via ViewBag and then rendering it with HTML.Raw, So I followed this here (and a a few others) but that code only pulls in the name of the property "MyPropertyName" and not string from the resource file.

Any ideas? Thanks.

Related posts

Recent Viewed