0

MVCのビューにグリッドを表示しようとしています。

WebGridにデータを入力しましたが、表示できませんか?

webGridの表示方法を教えてもらえますか?

MyViewのコードは次のとおりです。

@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

この行が必要です

@grid.GetHtml()
于 2012-09-27T12:28:41.733 に答える
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;
}
于 2012-09-27T12:59:02.393 に答える