ASP.NET MVC3 JSON Model-binding with nested class

前端 未结 2 1326
闹比i
闹比i 2020-12-24 15:13

In MVC3, is it possible to automatically bind javascript objects to models if the model has nested objects? My model looks like this:

 public class Tweet
 {
         


        
2条回答
  •  太阳男子
    2020-12-24 15:50

    I experienced the same issue, however in my case this was related to how the data was being transmitted from client side. Make sure the AJAX request is using the proper headers and formatting. For example:

        dataType: 'json',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify({
            MemberId : '123',
            UserName: '456',
            Parameters: [
                { Value : 'testing' },
                { Value : 'test2' }
            ]
        }),
    

提交回复
热议问题