加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

当我的模型在我的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,而不是直接传递一个字符串.如果有必要,这将使您有机会使用数据注释来提供有关该字段的其他数据.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读