我有一个控制器定义为:
[AcceptVerbs(HttpVerbs.Post)] public JsonResult PostMoreData(DataContracts.Address address,DataContracts.GeoLocation geoLocation) { return Json("test"); } where DataContracts.Address and DataContracts.GeoLocation are complex types.
从我的视图我试图使用jQuery发布如下:
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"); }
但是,在控制器上,我得到空值.
它可以工作,如果我的控制器只需要一个参数,我只发布一个对象.
[AcceptVerbs(HttpVerbs.Post)] public JsonResult PostMoreData(DataContracts.Address address) { return Json("test"); }
function PostMoreData() { var JsonAddress = { "Building": $('Building').val(),"MonthsAtAddress": $('MonthsAtAddress').val() }; jQuery.post("/AddressValidation/PostMoreData",JsonAddress,"json"); }
任何想法如何我可以发布多个对象?
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。