当我转到 cshtml 页面时出现此错误:
An exception of type 'System.ArgumentException' occurred in System.Web.Mvc.dll but was not handled in user code
在我的 cshtml 代码中:
<div class="form-group">
@Html.Label("Model", new { @class = "control-label col-md-4" })
<div class="col-md-8">
@Html.Editor("Model")
</div>
</div>
但另一方面,如果我在 @Html.Editor("PropertyModel")
它运行完美,没有发生错误。
更新:
在我的模型中:
public class PropertyAssign {
public int PropertyAssignId { get; set; }
public string PropertyName { get; set; }
public string Model { get; set; }
public DateTime AssignDate { get; set; }
}
在我的 Controller 中:
public ActionResult Create()
{
return View();
}
最佳答案
我试过这种情况,这很奇怪,但是使用 @Html.Editor() 帮助程序时,模型属性的标识符存在一些问题。
@Html.Editor("Model") // throws an exception
@Html.EditorFor(m => m.Model) // works fine
也许在这种情况下,模型的含义是传递给 View 的整个模型,而不是单个属性。但是当我将 Model 属性的标识符更改为其他标识符时,例如 SomeModel,一切都很好。
@Html.Editor("SomeModel") // works fine
@Html.EditorFor(m => m.SomeModel) // works fine
因此,可能的解决方案是:
- 更改您使用的编辑器助手或
- 更改您的属性(property)标识符
关于c# - 值不能为 null 或为空。\r\n参数名称 : name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36833138/