0

我正在尝试在 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);
  }
4

2 回答 2

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>

网站.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;
}
于 2012-09-27T12:59:02.393 回答
1

需要这条线

@grid.GetHtml()
于 2012-09-27T12:28:41.733 回答