[英]'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred
[英]Microsoft.CSharp.RuntimeBinder.RuntimeBinderException Error
我已經在此錯誤上停留了將近一天,而且我不明白為什么會得到它。
錯誤:
System.Core.dll中發生類型'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException'的異常,但未在用戶代碼中處理
附加信息:'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);
我有一種失敗的感覺,因為ViewBag是一種動態類型,並且它不知道Count是一個int且Bind方法期望rowCount是一個int。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.