简体   繁体   English

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException错误

[英]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.

相关问题 发生``Microsoft.CSharp.RuntimeBinder.RuntimeBinderException'' - 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred ASP.Net CORE 3.1 - 抛出错误异常:Microsoft.CSharp.dll 中的“Microsoft.CSharp.RuntimeBinder.RuntimeBinderException” - ASP .Net CORE 3.1 - Error Exception thrown: 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' in Microsoft.CSharp.dll 为什么Microsoft.CSharp.RuntimeBinder.RuntimeBinderException如果有调用的方法? - Why a Microsoft.CSharp.RuntimeBinder.RuntimeBinderException if the invoked method is there? 在私有类型上动态抛出Microsoft.CSharp.RuntimeBinder.RuntimeBinderException - Dynamic throwing Microsoft.CSharp.RuntimeBinder.RuntimeBinderException on private types 发生了“Microsoft.CSharp.RuntimeBinder.RuntimeBinderException”类型的第一次机会异常 - A first chance exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred #SpecFlow# For CreateDynamicInstance() - 错误 - Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:最佳重载方法 - #SpecFlow# For CreateDynamicInstance() - error - Microsoft.CSharp.RuntimeBinder.RuntimeBinderException : The best overloaded method LINQ加入Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:'对象'不包含以下内容的定义: - LINQ Join Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'object' does not contain a definition for 当我尝试在View中访问Model时出现Microsoft.CSharp.RuntimeBinder.RuntimeBinderException - Microsoft.CSharp.RuntimeBinder.RuntimeBinderException when I try to access Model in View 访问动态属性会引发“Microsoft.CSharp.RuntimeBinder.RuntimeBinderException”类型的异常 - Accessing a dynamic's property threw an exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:“System.__ComObject”不包含“语言”的定义 - Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: ''System.__ComObject' does not contain a definition for 'Language''
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM