Bry*_*yuk 4 html c# asp.net-mvc viewdata html-table
我的视图中有以下表格:
<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>
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我为此表创建一个主体并添加到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();
}
Run Code Online (Sandbox Code Playgroud)
但结果我得到了带有列标题的页面,但里面没有内容......源页面告诉我没有任何内容在...
试试这个:
<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>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6384 次 |
最近记录: |