문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top