DefaultModelBinder not binding nested model

前端 未结 5 1470
梦谈多话
梦谈多话 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:23

    This is what worked for me.

    I changed this:

    [HttpPost]
        public ActionResult Index(Person model)
        {
            return View(model);
        }
    

    To:

    [HttpPost]
        public ActionResult Index(FormCollection fc)
        {
            Person model = new Person();
            model.BillingInfo.BillingName = fc["BillingInfo.BillingName"]
    
            /// Add more lines to complete all properties of model as necessary.
    
            return View(model);
        }
    

提交回复
热议问题