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]: http://i.stack.imgur.com/atuGo.png
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前端其它相关文章!