当我的模型在我的ASP.NET MVC应用程序中为null时,EditorFor(..)
发布时间:2020-12-16 06:58:53 所属栏目:asp.Net 来源:网络整理
导读:我有一个非常简单的ASP.NET MVC View,它有一个简单的字符串作为模型. 例如. @model字符串 当我执行以下操作时,如果模型值为null(当用户首次登陆此视图/页面/资源时发生),则视图将引发异常. Value cannot be null or empty.Parameter name: nameDescription:
我有一个非常简单的ASP.NET MVC View,它有一个简单的字符串作为模型.
例如. @model字符串 当我执行以下操作时,如果模型值为null(当用户首次登陆此视图/页面/资源时发生),则视图将引发异常. Value cannot be null or empty. Parameter name: name Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentException: Value cannot be null or empty. Parameter name: name <td>@Html.EditorFor(model => model)</td> 当字符串模型值为null时,如何使用EditorFor(..)创建输入框? 解决方法
问题似乎是它无法确定它应该用作您正在创建的字段的名称.我建议传入一个带有单个字符串属性的ViewModel,而不是直接传递一个字符串.如果有必要,这将使您有机会使用数据注释来提供有关该字段的其他数据.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 在ASP.NET(C#)中创建动态RSS提要页面 – 我是否需要做额外的
- asp.net-mvc – asp.net mvc – 如何强制执行控制器层超类型
- asp.net-mvc – 通配符在asp.net mvc路由
- ASP.Net MVC:你可以在AJAX / jQuery调用中使用数据注释/验
- EventBus/EventQueue 再思考
- 是否有任何ASP.NET身份的实现具有另一个级别以上的帐户?
- asp.net-mvc – 使用PreCompiled网站运行自定义VirtualPath
- 自定义异常过滤特性
- asp.net-mvc-4 – 工作单元和通用存储库与实体框架5
- asp.net-mvc – 清除MVC 6 / ASP.NET 5中的输出缓存
推荐文章
站长推荐
- asp.net-mvc – jqgrid EF MVC:如何在excel中导
- (二)快速搭建 ASP.net core Web 应用
- 回发后的ASP.Net无法找到指定的URL
- asp.net-mvc – 在asp.net mvc中设置为Session的
- entity-framework – ASP .Net MVC与Java的[Tran
- asp.net – ashx处理程序DELETE请求不工作HTTP 4
- asp.net-mvc – ASP.NET MVC Json DateTime序列化
- asp.net – axd和ashx处理程序之间的区别
- asp.net-mvc-3 – 我可以在MVC3中扩展ModelState
- asp.net-mvc-4 – 发布后保留表单值(不是模型的一
热点阅读