动态MVC Webgrid不作为表绑定

时间:2018-02-08 05:27:52

标签: c# asp.net asp.net-mvc webgrid

Asp.net MVC我试图通过Viewbag将Web Grid Control作为动态从Controller传递,但是在View中没有正确呈现,只识别HTML标签,MVC标签仅显示为String,下面是我的代码

string htmlSTR = "<div class=\"slideClass\" id=\"SlideDiv\">@grid3.GetHtml(htmlAttributes: new { id = \"WebGridID1\" }, tableStyle: \"table table-responsive table-bordered\", headerStyle: \"header_table\", rowStyle: \"row_table\", alternatingRowStyle: \"alt-row_table\", columns: grid3.Columns(grid3.Column(columnName: \"RouteNumber\", header: \"Route Number\", style: \"table-class\"))) </div>";

        htmlSTR = htmlSTR.TrimStart('"');
        htmlSTR = htmlSTR.TrimEnd('"');
        ViewBag.HtmlStr = htmlSTR;

我正在使用@Html.Raw绑定从Controller传递的标记我的查看代码是@Html.Raw(ViewBag.HtmlStr)

但它没有正确绑定

<div class="slideClass" id="SlideDiv">@grid3.GetHtml(htmlAttributes: new { id = "WebGridID1" }, tableStyle: "table table-responsive table-bordered", headerStyle: "header_table", rowStyle: "row_table", alternatingRowStyle: "alt-row_table", columns: grid3.Columns(grid3.Column(columnName: "RouteNumber", header: "Route Number", style: "table-class"))) </div>

网格绑定为标签只是不作为表格,好心的是任何人指出我必须更改以将WebGrid绑定为表而不仅仅是标记

我在视图中提到的网格就像

<div class="slideClass">

    <div>
        @grid2.GetHtml(
            htmlAttributes: new { id = "WebGridID1" },
            tableStyle: "table table-responsive table-bordered",
            headerStyle: "header_table",
            rowStyle: "row_table",
            alternatingRowStyle: "alt-row_table",
            columns: grid1.Columns(
            grid2.Column(columnName: "RouteNumber", header: "Route Number", style: "table-class"),
            grid2.Column(columnName: "LoadReady", header: "Load Ready", style: "table-class"),
            grid2.Column(columnName: "SOD", header: "SOD", style: "table-class"),
            grid2.Column(columnName: "CutOff", header: "CutOff", style: "table-class"),
            grid2.Column(columnName: "EOD", header: "EOD", style: "table-class"),
            grid2.Column(columnName: "Settlement", header: "Settlement", style: "table-class"),
            grid2.Column(columnName: "Closed", header: "Closed", style: "table-class")))
    </div>
    @Html.Hidden("dir", grid2.SortDirection)
    @Html.Hidden("col", grid2.SortColumn)

</div>

0 个答案:

没有答案