我正试图在我的MVC视图中显示一个网格。
我已经填充了一个WebGrid,但我无法显示它?
有人可以告诉我如何显示webGrid吗?
我的观点代码如下:
@model MvcResComm.Models.ReturnProperties
@{
ViewBag.Title = "ShowProperties";
}
<h2>Select Property</h2>
@using System.Dynamic
@{
var result = new List<dynamic>();
foreach (var emprow in Model.DDS)
{
var row = (IDictionary<string, object>)new ExpandoObject();
Dictionary<string, object> eachEmpRow = (Dictionary<string, object>)emprow;
foreach (KeyValuePair<string, object> keyValuePair in eachEmpRow)
{
row.Add(keyValuePair);
}
result.Add(row);
}
var grid = new WebGrid(result);
}
答案 0 :(得分:1)
这条线是必需的
@grid.GetHtml()
答案 1 :(得分:1)
@using System.Dynamic
<div>
@{
var result = new List<dynamic>();
foreach (var emprow in Model.DDS)
{
var row = (IDictionary<string, object>)new ExpandoObject();
Dictionary<string, object> eachEmpRow = (Dictionary<string, object>)emprow;
foreach (KeyValuePair<string, object> keyValuePair in eachEmpRow)
{
row.Add(keyValuePair);
}
result.Add(row);
}
var grid = new WebGrid(result);
}
@grid.GetHtml(
tableStyle: "grid",
headerStyle: "grid-header",
alternatingRowStyle: "grid-alternating-row",
selectedRowStyle: "grid-selected-row",
rowStyle: "grid-row-style"
)
</div>
的site.css
.grid
{
width: 50%;
border: 0px;
border-collapse: collapse;
}
.grid a
{
color: #000;
}
.grid-row-style td
{
text-align:center
}
.grid-header th
{
padding-right:20px;
padding-left:20px;
}
.grid-alternating-row td
{
text-align:center
}
.grid-header
{
padding: 6px 5px;
text-align: center;
background-color: #e8eef4;
border-bottom: 2px solid #3966A2;
height: 40px;
border-top: 2px solid #D6E8FF;
border-left: 2px solid #D6E8FF;
border-right: 2px solid #D6E8FF;
}
.grid-footer
{
padding: 6px 5px;
text-align: center;
background-color: #e8eef4;
border-top: 2px solid #3966A2;
height: 30px;
border-bottom: 2px solid #D6E8FF;
border-left: 2px solid #D6E8FF;
border-right: 2px solid #D6E8FF;
}
.grid-alternating-row
{
height: 30px;
background-color: #f2f2f2;
border-bottom: 1px solid #d2d2d2;
border-left: 2px solid #D6E8FF;
border-right: 2px solid #D6E8FF;
}
.grid-row-style
{
height: 30px;
border-bottom: 1px solid #d2d2d2;
border-left: 2px solid #D6E8FF;
border-right: 2px solid #D6E8FF;
}
.grid-selected-row
{
font-weight: bold;
}