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