Reputation: 5089
I'm writing some custom Html Helpers for my MVC3 and soon MVC4 project. Examples on the net usually show that it's done with MvcHtmlString, however, I read that if we are using .NET 4, we should be using HtmlString.
What should I use and why?
Thanks.
Upvotes: 3
Views: 692
Reputation: 1039090
Always use the highest possible interface/class in the hierarchy when designing something. In this case it's IHtmlString and you could use it in ASP.NET MVC 3 and 4.
public IHtmlString Foo(this HtmlHelper helper)
{
return new HtmlString("foo bar");
}
Be careful when returning an IHtmlString
instance from your helper. This means that it is up to you to properly HTML encode it:
Upvotes: 4