HtmlString vs. MvcHtmlString

前端 未结 3 585
陌清茗
陌清茗 2020-11-29 03:57

HtmlString vs. MvcHtmlString

What are the differences bettween those two, or when to prefer one over the other?

Edit:

相关标签:
3条回答
  • 2020-11-29 04:13

    HtmlString only exists in ASP.NET 4.

    MvcHtmlString was 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 of HtmlString presumably for MVC 2->3 for source compatibility.

    If you're ever going to drop back to MVC 2 it might make sense to use IHtmlString or var for values returned from MVC functions. Alternatively I think you can now just switch to HtmlString throughout.

    0 讨论(0)
  • 2020-11-29 04:29

    HtmlString was only introduced in .Net 4.0.

    In ASP.Net 3.5 MVC 2.0, you should use MvcHtmlString.
    In .Net 4.0, you should use HtmlString. (which is simpler)

    0 讨论(0)
  • 2020-11-29 04:32

    MvcHtmlString is used to indicate when a string should not be re-encoded.

    See What is an MvcHtmlString and when should I use it?

    and

    What does <%: %> do in ASP.NET (MVC2)?

    0 讨论(0)
提交回复
热议问题