DefaultModelBinder not binding nested model

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

    public class MyNestedClass
    {
        public string Email { get; set; }
    }
    
    public class LoginModel
    {
    //If you name the property as 'xmodel'(other than 'model' then it is working ok.
    public MyNestedClass xmodel  {get; set;} 
    
    //If you name the property as 'model', then is not working
    public MyNestedClass model  {get; set;} 
    
    public string Test { get; set; }
    }
    

    I have had the similiar problem. I spent many hours and find the problem accidentally that I should not use 'model' for the property name

    @Html.TextBoxFor(m => m.xmodel.Email) //This is OK
    @Html.TextBoxFor(m => m.model.Email) //This is not OK
    

提交回复
热议问题