Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can't use embedded razor strings within the lambda expression, as @Alessandro D'Andra suggests you have to use <code>x =&gt; "&lt;img src='" + someString + "'&gt;&lt;/img&gt;";</code> instead.</p> <p>You might also have to wrap it all in an <code>MvcHtmlString</code> to prevent Razor from escaping the string once it is used by the formatter, but I don't know exactly how the formatter works - you have to try it.</p> <p>I made a small test file to find out exactly what the Razor compiler would do with your code. This is the razor file:</p> <pre><code>@{ string someString = "somestring"; Func&lt;object, object&gt; a = x =&gt; "&lt;text&gt;&lt;img src='" + someString + "'&gt;&lt;/img&gt;&lt;/text&gt;"; Func&lt;object, object&gt; b = x =&gt; @&lt;text&gt;&lt;img src="@someString"&gt;&lt;/img&gt;&lt;/text&gt;); } </code></pre> <p>The ASP.NET compiler creates this C# code out of it (only relevant parts included):</p> <pre><code> string someString = "somestring"; Func&lt;object, object&gt; a = x =&gt; "&lt;text&gt;&lt;img src='" + someString + "'&gt;&lt;/img&gt;&lt;/text&gt;"; Func&lt;object, object&gt; b = x =&gt; #line default #line hidden item =&gt; new System.Web.WebPages.HelperResult(__razor_template_writer =&gt; { BeginContext(__razor_template_writer, "~/Views/Home/Index.cshtml", 210, 4, true); WriteLiteralTo(__razor_template_writer, "&lt;img"); EndContext(__razor_template_writer, "~/Views/Home/Index.cshtml", 210, 4, true); WriteAttributeTo(__razor_template_writer, "src", Tuple.Create(" src=\"", 214), Tuple.Create("\"", 231) #line 7 "c:\temp\MvcApplication1\Views\Home\Index.cshtml" , Tuple.Create(Tuple.Create("", 220), Tuple.Create&lt;System.Object, System.Int32&gt;(someString #line default #line hidden , 220), false) ); BeginContext(__razor_template_writer, "~/Views/Home/Index.cshtml", 232, 7, true); WriteLiteralTo(__razor_template_writer, "&gt;&lt;/img&gt;"); EndContext(__razor_template_writer, "~/Views/Home/Index.cshtml", 232, 7, true); </code></pre> <p>Using the embedded text syntax <code>@&lt;text&gt;</code> within the lambda expression creates obviously incorrect C# code. It is not smart enough to make the embedded tags part of the lambda expression, instead it breaks the lambda expression by inserting code to emit the embedded text right away.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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