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

asp.net-mvc – MVC帖子没有填充模型

发布时间:2020-12-16 06:37:46 所属栏目:asp.Net 来源:网络整理
导读:我无法弄清楚为什么我的模型没有被填充.发布的所有数据都在Request.Form中,但该模型实际上是空的. 根据this answer on model with collection not populating on postback In other words,(…) If any required fields are missing,or if the values are sub
我无法弄清楚为什么我的模型没有被填充.发布的所有数据都在Request.Form中,但该模型实际上是空的.

根据this answer on model with collection not populating on postback

In other words,(…) If any required fields are missing,or if the values are
submitted in such a way that they cannot be converted to the type of a required field,then the entire object will be left null

我已经更改了几种值类型,但我无法使其工作.

这是我的模型:

public class AddModel
{
    //Get properties 
    public Vehicle vehicle; 

    //Post properties 
    [Required(ErrorMessage = "Please enter a start date")]
    public DateTime StartDate; 
    public int? StatusCode; 

    public SelectList StatusCodes()
    {
         ...
    } 
}

你能想到为什么它没有被填充吗?

解决方法

制作AddModel成员属性 – 添加get;组;到字段应该解决你的问题

(编辑:李大同)

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

    推荐文章
      热点阅读