2016-11-22 19 views
1

ASP.NET MVC4でExpand/Collapseを使用してネストされたWebGridを使用していますが、エラーが発生します。メソッドが見つかりませんでした: 'System.Collections.Generic。 IDictionary`2 System.Web.WebPages.Html.HtmlHelper.ObjectToDictionary(System.Object) '。、私は本当にこのエラーを解決する方法を知らない。助けてください。@ grid.GetHtmlメソッドがasp.net MVCビューで見つかりません

マイビューモデル

public class PackagesVM 
{ 
    public Packages package { get; set; } 
    public List<Lot> packLots { get; set; } 
} 

マイコントローラー

public ActionResult GetPackagesLot() 
    { 
     List<PackagesVM> packagesLots = new List<PackagesVM>(); 

     // here MyDatabaseEntities is our data context 
     using (Entities db = new Entities()) 
     { 
      var pack = db.Packages1.OrderByDescending(a => a.id); 
      foreach (var i in pack) 
      { 
       var lot = db.Lots.Where(a => a.pack_id==i.id).ToList(); 
       packagesLots.Add(new PackagesVM { package = i, packLots = lot }); 
      } 
     } 
     return View(packagesLots); 
    } 

マイビュー

<div id="main" style="padding:25px; background-color:white;"> 
@grid.GetHtml(
htmlAttributes: new {id="gridT", width="700px" }, 
columns:grid.Columns(
     grid.Column("package.Id","Pack ID"), 
     grid.Column("package.Name","Package Name"), 
     grid.Column("package.Province_id","Province"), 
     grid.Column(header:"Create at",format:(item)=> string.Format("{0:dd-MM-yyyy}",item.package.created_at)), 

     grid.Column(format:(item)=>{ 
      WebGrid subGrid = new WebGrid(source: item.packLots); 
      return subGrid.GetHtml(
       htmlAttributes: new { id="subT" }, 
       columns:subGrid.Columns(
         subGrid.Column("id","Id"), 
         subGrid.Column("lot_number", "Lot Number"), 
         subGrid.Column("pack_id", "Package ID"), 
         subGrid.Column("contracted_amount", "Amount") 
        )      
       ); 
     }) 
    ) 
) 

私のスクリプト

@section Scripts{ 
<script> 
    $(document).ready(function() { 
     var size = $("#main #gridT > thead > tr >th").size(); // get total column 
     $("#main #gridT > thead > tr >th").last().remove(); // remove last column 
     $("#main #gridT > thead > tr").prepend("<th></th>"); // add one column at first for collapsible column 
     $("#main #gridT > tbody > tr").each(function (i, el) { 
      $(this).prepend(
        $("<td></td>") 
        .addClass("expand") 
        .addClass("hoverEff") 
        .attr('title',"click for show/hide") 
       ); 

      //Now get sub table from last column and add this to the next new added row 
      var table = $("table", this).parent().html(); 
      //add new row with this subtable 
      $(this).after("<tr><td></td><td style='padding:5px; margin:0px;' colspan='" + (size - 1) + "'>" + table + "</td></tr>"); 
      $("table", this).parent().remove(); 
      // ADD CLICK EVENT FOR MAKE COLLAPSIBLE 
      $(".hoverEff", this).live("click", function() { 
       $(this).parent().closest("tr").next().slideToggle(100); 
       $(this).toggleClass("expand collapse"); 
      }); 
     }); 

     //by default make all subgrid in collapse mode 
     $("#main #gridT > tbody > tr td.expand").each(function (i, el) { 
      $(this).toggleClass("expand collapse"); 
      $(this).parent().closest("tr").next().slideToggle(100); 
     }); 

    }); 
</script> 

エラー } enter image description here

+0

を追加してください。このサンプルにアクセスしてください:http://www.dotnetfunda.com/articles/show/3139/webgrid-in -aspnet-mvc –

答えて

0

はあなたのビューファイルでBeginFormブロック内のコード行を次のようにグリッドを定義する必要があります。

var grid = new WebGrid(Model.PackagesVM, canSort: false); 
0

もこのnugetパッケージAD.System.Web.Helpers.dll

+1

これがうまくいかない理由についての説明を実際に追加する必要があります。コメント付きのサンプルコードを追加することもできます。現在のフォームでは、コミュニティの他の人が問題を解決/答えました。 – ishmaelMakitla

関連する問題