How to send nested json object to mvc controller using ajax

后端 未结 3 1001
太阳男子
太阳男子 2020-12-22 04:20

I am working on an ASP.NET MVC application. I have the following view model in c#:

public class ContactModel
{
    public string Address { get; set; }
    pu         


        
3条回答
  •  北海茫月
    2020-12-22 05:00

    You need for format your string to proper json -

    Say if you model is -

    public class ContactModel
    {
        public string Address { get; set; }
        public string City { get; set; }
        public string State { get; set; }
    }
    
    public class PersonModel
    {
        public ContactModel Contact { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Profession { get; set; }
    }
    

    Then you AJAX Post should be like this -

    
    

    Then output is going to be -

    enter image description here

提交回复
热议问题