Asp.net core model doesn't bind from form

后端 未结 10 903
没有蜡笔的小新
没有蜡笔的小新 2021-02-02 13:54

I catch post request from 3rd-side static page (generated by Adobe Muse) and handle it with MVC action.

10条回答
  •  醉酒成梦
    2021-02-02 14:23

    I have run in to this issue where the model does not bind when I have more than one constructor on the underlying model like:

    public class EmailModel
    {
        public EmailModel()
        {}
    
        public EmailModel(string _name, string _company)
        {
            Name = _name;
            Company = _company;
        }
        public string Name { get; set; }
        public string Email { get; set; }
        public string Company { get; set; }
        public string Phone { get; set; }
        public string Additional { get; set; }
    }
    

    Fixed by removing all but one constructor like this:

    public class EmailModel
    {
        public EmailModel()
        {}
    
        public string Name { get; set; }
        public string Email { get; set; }
        public string Company { get; set; }
        public string Phone { get; set; }
        public string Additional { get; set; }
    }
    

提交回复
热议问题