Chase Florell
Chase Florell

Reputation: 47407

ASP.NET MVC - How can I build an HtmlHelper that doesn't need to be Wrapped in MvcHtmlString?

When I use the build in Html Helpers, I can simply write the following.

@Html.Actionlink(bla)

But when I write my own Html Helpers, I need to block the encoding by wrapping it in a MvcHtmlString

@MvcHtmlString.Create(Html.CustomPager(bla))

Is there anything I can do in the extension method so that I don't have to worry about "not" encoding it?

Upvotes: 2

Views: 537

Answers (1)

jim tollan
jim tollan

Reputation: 22485

yes, you can make the helper return a MvcHtmlString - i.e:

public static MvcHtmlString Css(this HtmlHelper html, string path)
{
    return MvcHtmlString.Create(/* some code*/);
}

rather than:

public static string Css(this HtmlHelper html, string path)
{
    return (/* some code*/);
}

i don't know the razor requirements, so this is a blind stab in the dark answer perhaps..

Upvotes: 5

Related Questions