简体   繁体   English

MVC5 Razor 值不能为 null 或为空。 参数名称:名称

[英]MVC5 Razor Value cannot be null or empty. Parameter name: name

Source error: Line 22: @Html.TextBoxFor(model => model.DailyCurrencyRates___BuyingCurrency, new { @id = "test", @class = "form-control" })源错误:第 22 行:@Html.TextBoxFor(model => model.DailyCurrencyRates___BuyingCurrency, new { @id = "test", @class = "form-control" })

I am stuck on this issue for days and cannot get round this error.我被这个问题困了好几天,无法解决这个错误。 I simply want to render a partial view with the items for parent class.我只想用父类的项目呈现部分视图。 below is my code: Please ask for more info if needed.以下是我的代码:如果需要,请询问更多信息。

Controller控制器

public ActionResult AddRecord(int index)
{
  return PartialView("_AddItem", new ForexItem { Index = index});
}

Parent View父视图

@foreach (ForexItem item in Model.ForexItems)
{
    Html.RenderPartial("_AddItem", item);
}

Partial View局部视图

@model F.Models.Entities.ForexItem

@Html.TextBoxFor(model => model.DailyCurrencyRates___BuyingCurrency, new { @id = "test", @class = "form-control" })

Model模型

public partial class ForexItem
 {
        public int ID { get; set; }

        [NotMapped]
        [StringLength(1000)]
        [Display(Name = "Buying")]
        public string DailyCurrencyRates___BuyingCurrency { get; set; }

        [NotMapped]
        public int Index { get; set; }
}

I obtained that same vague, obscure error when I increased the number of underscores in a model property name from 1 to 2. Note that the error did not occur for the LabelFor Helper directly before the TextBoxFor helper, but just in the TextBoxFor helper, same as you got.当我将模型属性名称中的下划线数量从 1 增加到 2 时,我得到了同样模糊、模糊的错误。请注意,在 TextBoxFor 助手之前的 LabelFor Helper 没有发生该错误,而只是在 TextBoxFor 助手中,相同如你所见。 (I notice your property name ("DailyCurrencyRates___BuyingCurrency") has 3 underscores.) It then went away when I removed the extra underscore from the property name. (我注意到您的属性名称(“DailyCurrencyRates___BuyingCurrency”)有 3 个下划线。)然后当我从属性名称中删除额外的下划线时它就消失了。 It was as though with the extra underscore, Razor could not find the property name, so it just searched for (generic) "name" instead, which it also could not find.好像有了额外的下划线,Razor 找不到属性名称,所以它只是搜索(通用)“名称”,它也找不到。

It may be a typo, but it seems to me that you should change Model.ForexItems to Model.ForexItem - no s.这可能是一个错字,但在我看来,您应该将Model.ForexItems更改为Model.ForexItem - 没有。 Based on your submitted code.根据您提交的代码。 … or maybe just use Model since you already put ForexItem in as that? ……或者也许只是使用Model因为您已经将 ForexItem 放入其中?

Parent View父视图

@foreach (ForexItem item in Model)
{
    Html.RenderPartial("_AddItem", item);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复 MVC 应用程序中的“System.ArgumentException:'值不能为 null 或为空。参数名称:名称'”? - How to fix a "System.ArgumentException: 'Value cannot be null or empty. Parameter name: name'" in a MVC app? 值不能为 null 或为空。 参数名称linkText - Value cannot be null or empty. Parameter name linkText 收到错误值不能为null或为空。 参数名称:URL - Getting an error Value cannot be null or empty. Parameter name: URL 值不能为空。 参数名称:MVC5(DropDownlist)项目 - Value cannot be null. Parameter name: items MVC5(DropDownlist) 值不能为null或为空。\ r \ nParameter name:name - Value cannot be null or empty.\r\nParameter name: name 值不能为空。 参数名称:项目(在下拉列表中)ASP.NET MVC5 - Value cannot be null. Parameter name: items (in Dropdown List) ASP.NET MVC5 联系表格无效,“值不能为null。 参数名称:地址” MVC5 - Contact form doesn't work, “Value cannot be null. Parameter name: address” MVC5 无法通过连接字符串连接到Dynamics CRM Online。 组织不能为null或为空。 参数名称:组织名称 - Unable to connect via connection string to Dynamics CRM Online. Organization cannot be null or empty. Parameter name: Organization Name ASP.NET Identity CreateAsync返回错误“名称不能为null或为空。” - ASP.NET Identity CreateAsync returning Error “Name cannot be null or empty.” 在mvc5中排序,以列名作为参数分页 - Sorting,Paging in mvc5 with column name as parameter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM