Problem with MVC3 ascx vs razor

I have an aspx webpage that displays correctly. When converting to a razor, this is not so. Here is a simplified example (devoid of all extraneous things).

Aspx:

   <asp:Content ID="indexContent" ContentPlaceHolderID="ToolContent" runat="server">
      <% string test = "<div><b>Tag Test</b></div>"; %>
      <h2><%= test %></h2>
   </asp:Content>

Razor:

   @section ToolContent {
      @{ string test = "<div><b>Tag Test</b></div>"; }
      <h2>@test</h2>
   }

Aspx displays as expected. The shaver simply displays the contents of the test test (<div> <b> Tag Tag </b> </div>) in the title tag.

I guess my understanding of razors is wrong. If someone could enlighten me and / or show me a solution / work, I would really appreciate it.

+3
source share
1 answer

When you write @test, Razor automatically eludes him.

To prevent its screening, write @Html.Raw(test).

+10
source

All Articles