2014-10-09 8 views
0

나는 거의 하루 동안이 오류에 갇혀 있었고 왜 나는 그것을 얻고 있는지 이해할 수 없습니다.Microsoft.CSharp.RuntimeBinder.RuntimeBinderException 오류

오류 :

An exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in System.Core.dll but was not handled in user code

추가 정보 : '에 가장 적합한 오버로드 된 메서드 일치 System.Web.Helpers.WebGrid.Bind

컨트롤러 :

var data = (from brand in db.Brand 
      from division in db.Division 
      from supplier in db.Supplier 
      where brand.BrandID == division.DivisionID 
      where product.SupplierID == supplier.SupplierID 
      select new ModelGrid 
      { 
        BrandID = brand.BrandID, 
        BrandName = brand.BrandName, 
        DivisionName = division.DivisionName, 
        CompanyName = supplier.CompanyName, 
        ContactName = supplier.ContactName, 
        Country = supplier.Country 
      }).ToList(); 

    return View(data); 

보기 :

WebGrid grid = new WebGrid(Model); 
grid.Bind(Model, rowCount: ViewBag.count, autoSortAndPage: false); 

@grid.GetHtml(
    columns: grid.Columns(
     grid.Column("BrandID", "Brand ID", canSort: true), 
     grid.Column("BrandName", "Brand Name", canSort: true), 
     grid.Column("DivisionName", "Division Name", canSort: true), 
     grid.Column("CompanyName", "Company Name", canSort: true), 
     grid.Column("ContactName", "Contact Name", canSort: true), 
     grid.Column("Country", "Country", canSort: true) 
    ) 
) 

및 모델 : 익명 형식을 사용하는 경우이 오류가 보인다 내가 그것을 찾을 수 있습니다에서

public class ModelGrid 
{ 
    public int BrandID { get; set; } 
    public string BrandName { get; set; } 
    public string DivisionName { get; set; } 
    public string CompanyName { get; set; } 
    public string ContactName { get; set; } 
    public string Country { get; set; } 
} 

그러나 나는이 피할 생각했다. 나는 아직도이 시점에서 배우고 있으므로 조언을 많이 주시면 감사하겠습니다. 이

grid.Bind(Model, rowCount: (int)ViewBag.count, autoSortAndPage: false); 

를 작동하는 경우

답변

0

이 시도하고 참조 내가 가지고 ViewBag 동적 타입이며 그 백작은 INT과 바인딩 방법은 rowCount의 int를 기대 모르기 때문에 그 실패를 느낌.

+0

감사합니다. 실제로이 문제는 아니지만 문제가 무엇인지를 보여주었습니다. 나는 ViewBag.count와 같은 정확한 정보를 전달하지 않고 있으며, 문제가있는 시간을 필자가 볼 수는 없었습니다. 어쨌든 제가 문제를 찾도록 도와 주신 것에 대해 다시 한번 감사드립니다. – user3539718