5

我的视图中有下表:

<table id="tblHelpRow">
    <thead>
        <tr class="title">
            <th>
                1
            </th>
            <th>
                2
            </th>
            <th>
                3
            </th>
            <th>
                4
            </th>
        </tr>
    </thead>
    <tbody id="helpRowBody">       
        @{ ViewData["MattersTable"].ToString(); }
    </tbody>
</table>

在我的控制器中,我为该表创建了一个主体并添加到 DataView。我通过从另一个重定向并传递我的 DataTable 来到达这个控制器。实际上我有一点不同,但在这里我写得尽可能简单以显示问题:

public ActionResult Matters(DataTable source)
{
       string result = "";
       foreach(DataRow dr in source.Rows)
       {
            result += "<tr>" +
            "<td>" + dr["1"] + "</td>" +
            "<td>" + dr["2"] + "</td>" +
            "<td>" + dr["3"] + "</td>" +
            "<td>" + dr["4"] + "</td>" +
            "</tr>";
       }
       ViewData["MattersTable"] = result;
       return View();
}

但结果我得到了带有列标题但里面没有内容的页面......源页面告诉我tbody里面什么都没有......

4

1 回答 1

7

尝试这个:

<table id="tblHelpRow">
    <thead>
        <tr class="title">
            <th>
                1
            </th>
            <th>
                2
            </th>
            <th>
                3
            </th>
            <th>
                4
            </th>
        </tr>
    </thead>
    <tbody id="helpRowBody">       
        @Html.Raw(ViewData["MattersTable"])
    </tbody>
</table>
于 2013-11-12T22:45:43.327 回答