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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With