DefaultModelBinder not binding nested model

前端 未结 5 1471
梦谈多话
梦谈多话 2020-12-31 09:57

Looks like others have had this problem but I can\'t seem to find a solution.

I have 2 Models: Person & BillingInfo:

public class Person
{
 publi         


        
5条回答
  •  一个人的身影
    2020-12-31 10:16

    I had this problem, and the answer was staring me in the face for a few hours. I'm including it here because I was searching for nested models not binding and came to this answer.

    Make sure that your nested model's properties, like any of your models that you want the binding to work for, have the correct accessors.

        // Will not bind!
        public string Address1;
        public string Address2;
        public string Address3;
        public string Address4;
        public string Address5;
    
    
        // Will bind
        public string Address1 { get; set; }
        public string Address2 { get; set; }
        public string Address3 { get; set; }
        public string Address4 { get; set; }
        public string Address5 { get; set; }
    

提交回复
热议问题