HtmlString vs. MvcHtmlString
What are the differences bettween those two, or when to prefer one over the other?
Edit:
One thing to prefer MvcHtmlString over HtmlString is the extension method IsNullOrEmpty of MvcHtmlString.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
HtmlStringonly exists in ASP.NET 4.MvcHtmlStringwas a compatibility shim added to MVC 2 to support both .NET 3.5 and .NET 4. Now that MVC 3 is .NET 4 only, it’s a fairly trivial subclass ofHtmlStringpresumably for MVC 2->3 for source compatibility.If you’re ever going to drop back to MVC 2 it might make sense to use
IHtmlStringorvarfor values returned from MVC functions. Alternatively I think you can now just switch toHtmlStringthroughout.