Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is an excellent opportunity to look at the source code that's available to us for ASP.NET (<a href="http://aspnetwebstack.codeplex.com" rel="noreferrer">http://aspnetwebstack.codeplex.com</a>).</p> <p>Looking at HtmlHelper.cs, this is the code for <code>Html.Raw()</code>:</p> <pre><code>public IHtmlString Raw(string value) { return new HtmlString(value); } public IHtmlString Raw(object value) { return new HtmlString(value == null ? null : value.ToString()); } </code></pre> <p>And this is the code for the MvcHtmlString class:</p> <pre><code>namespace System.Web.Mvc { public sealed class MvcHtmlString : HtmlString { [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "MvcHtmlString is immutable")] public static readonly MvcHtmlString Empty = Create(String.Empty); private readonly string _value; public MvcHtmlString(string value) : base(value ?? String.Empty) { _value = value ?? String.Empty; } public static MvcHtmlString Create(string value) { return new MvcHtmlString(value); } public static bool IsNullOrEmpty(MvcHtmlString value) { return (value == null || value._value.Length == 0); } } } </code></pre> <p>The most significant difference is that <code>Html.Raw()</code> accepts any object, while <code>MvcHtmlString.Create()</code> only accepts strings. Also, <code>Html.Raw()</code> returns an interface, while the Create method returns an MvcHtmlString object. Lastly, the Create deals with null differently.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload