所以我通过 AJAX 对控制器方法执行 GET 以返回一些 JSON。返回 JSON 很好,但是发送参数来构造一个简单的对象却不行——结果是该对象的默认值!
有任何想法吗?
模型:
public class CoreViewModel
{
public int Id {get; set;}
public int ExtensionId {get;set;}
public string Zip {get; set;}
public int ShopId {get; set;}
}
控制器:
public ActionResult GetDetails(CoreViewModel model)
{
return Json(new DetailsViewModel(model), JsonRequestBehavior.AllowGet);
}
阿贾克斯:
$.ajax({
type: "GET",
url: serviceUrl + "GetDetails/",
contentType: "application/json; charset=utf-8",
crossDomain: false,
cache: false,
dataType: 'json',
data: '{"Zip":"@Model.Zip","ShopId":@Model.ShopId,"ExtensionId":@Model.ExtensionId,"Id":@Model.Id}',
success: function(data) {
};
},
......