[英]Microsoft.CSharp.RuntimeBinder.RuntimeBinderException Error
I've been stuck on this error for almost a day now and I don't understand why I am getting it. 我已经在此错误上停留了将近一天,而且我不明白为什么会得到它。
The error: 错误:
An exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in System.Core.dll but was not handled in user code
System.Core.dll中发生类型'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException'的异常,但未在用户代码中处理
Additional information: The best overloaded method match for 'System.Web.Helpers.WebGrid.Bind 附加信息:'System.Web.Helpers.WebGrid.Bind的最佳重载方法匹配
Controller: 控制器:
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);
View: 视图:
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)
)
)
and Model: 和型号:
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; }
}
From what I can find it seems you get this error when using anonymous types, however I thought I had avoided this. 据我发现,使用匿名类型时似乎会出现此错误,但是我认为我避免了这种情况。 I am still learning at this point so any advice is much appreciated.
此时我仍在学习,因此任何建议都将不胜感激。
Try this and see if it works 试试这个,看看是否有效
grid.Bind(Model, rowCount: (int)ViewBag.count, autoSortAndPage: false);
I have a feeling its failing because ViewBag is a dynamic type and it doesn't know that Count is an int and Bind method expects an int for rowCount. 我有一种失败的感觉,因为ViewBag是一种动态类型,并且它不知道Count是一个int且Bind方法期望rowCount是一个int。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.