mapping ajax data in c# using object binder

The following screen shot shows the data I'm sending (shown with firebug in firefox). The code below then shows the method the ajax method calls. The Date and Id properties are correctly populated when hitting the server side method call but my array (of type CustomerRequests) has no values inside it, however the number of CustomerRequests in the post is correct. Any ideas? Thanks ![enter image description here][1] [1]: My Controller method public ActionResult Show(Customers request) { .. // Number of request.CustomerRequests is correct // Although request.CustomerRequests[0].Name == null ?? which is wrong Customers class below: [DataContract] public class Customers { [DataMember] public CustomerRequests[] CustomerRequests{ get; set; } [DataMember] public DateTime Date { get; set; } // I can see this value [DataMember] public int Id{ get; set; } // I can see this value } [DataContract] public class CustomerRequests { [DataMember] public string Name { get; set; } [DataMember] public string Expression { get; set; } } Javascript $('textarea').each(function () { var theName = 'The Name'; var theExpression = 'The Expression'; var obj = { 'Name': theName, 'Expression': theExpression }; expressionArray.push(obj); }); // close each // val is the posted data var val = { 'Id': '1', 'Date': '2013-10-10', 'CustomerRequests': $.makeArray(expressionArray) }; I've tried although it doesn't work. JSON.stringify({ Customers: val })
I'd like to confirm the comment inside your action: request.CustomerRequests.length is 3 (according to the screenshot) but their properties are empty. Is that correct? Btw, well formated and complete question, congrats.

以上就是mapping ajax data in c# using object binder的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准