Search code examples
c#asp.net-mvcwebgrid

WebGrid MVC3 renders as string instead of Html


I'm using MVC3 WebGrid, and got this simplest cshtml, that won't work

@model IEnumerable<MyNamespace.MyClass>
@{
    var grid = new WebGrid(source: Model);
}
@grid.GetHtml()

But this code, do work

@model IEnumerable<MyNamespace.MyClass>
@{
    var grid = new WebGrid(source: Model);
}

@MvcHtmlString.Create(grid.GetHtml().ToHtmlString())

Question: The first and simpler code renders as string instead of Html... what could possibly make the first code to fail, and obligates me to use the second way?


Solution

  • Apparently someone who went through the project didn't know MVC already takes care of html characters rendered in the View...

    We had in Web.Config:

    <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <pages pageBaseType="MyNamespace.Views.MyViewPage">
          <namespaces>
            ...
          </namespaces>
        </pages>
    </system.web.webPages.razor>
    

    And MyViewPage was messing around some Helpers and other linstructions like Html.Raw