I have a controller defined as:
[AcceptVerbs(HttpVerbs.Post)] public JsonResult PostMoreData(DataContracts.Address address, DataContracts.GeoLocation geoLocation) { return Json("test"); } where DataContracts.Address and DataContracts.GeoLocation are complex types.
From my View i'm trying to post using jQuery as such:
function PostMoreData() { var JsonAddress = { "Building": $('Building').val(), "UnitNumber": $('UnitNumber').val(), "StreetNumber": $('StreetNumber').val(), "StreetName": $('StreetName').val(), "StreetType": $('StreetType').val(), "Suburb": $('Suburb').val(), "State": $('State').val(), "Postcode": $('Postcode').val(), "MonthsAtAddress": $('MonthsAtAddress').val() }; var JsonGeoLocation = { "Latitude": $('Latitude').val(), "Longitude": $('Longitude').val() }; jQuery.post("/AddressValidation/PostMoreData", {address: JsonAddress, geoLocation: JsonGeoLocation}, function(data, textStatus) { if (textStatus == "success") { var result = eval(data); if (result.length > 0) { alert(result); } } }, "json"); }
However, on the controller, I get nulls.
It works if my Controller takes just 1 argument and I post just one object.
[AcceptVerbs(HttpVerbs.Post)] public JsonResult PostMoreData(DataContracts.Address address) { return Json("test"); }
function PostMoreData() { var JsonAddress = { "Building": $('Building').val(), "UnitNumber": $('UnitNumber').val(), "StreetNumber": $('StreetNumber').val(), "StreetName": $('StreetName').val(), "StreetType": $('StreetType').val(), "Suburb": $('Suburb').val(), "State": $('State').val(), "Postcode": $('Postcode').val(), "MonthsAtAddress": $('MonthsAtAddress').val() }; jQuery.post("/AddressValidation/PostMoreData", JsonAddress, function(data, textStatus) { if (textStatus == "success") { var result = eval(data); if (result.length > 0) { alert(result); } } }, "json"); }
Any ideas how i can post more than one object?