我的视图中有以下表格:
1
2
3
4
@{ ViewData["MattersTable"].ToString(); }
在我的控制器中,我为此表创建一个主体并添加到DataView.我通过从另一个控制器重定向并传递我的DataTable来到达此控制器.在实际中我有点不同,但在这里我写的尽可能简单,以显示问题:
public ActionResult Matters(DataTable source)
{
string result = "";
foreach(DataRow dr in source.Rows)
{
result += "
" +"
" + dr["1"] + "" +"
" + dr["2"] + "" +"
" + dr["3"] + "" +"
" + dr["4"] + "" +"
";}
ViewData["MattersTable"] = result;
return View();
}
但结果我得到了带有列标题的页面,但里面没有内容……源页面告诉我没有任何内容在…
解决方法:
试试这个:
1
2
3
4
@Html.Raw(ViewData["MattersTable"])
标签:c,html-table,asp-net-mvc,html,viewdata
来源: https://codeday.me/bug/20190529/1176059.html