0

所以我通过 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) {

                    };

                },

......

4

2 回答 2

0

固定的。

从开头和结尾删除 '。(单引号)

于 2013-09-27T00:19:05.693 回答
0

尝试如下发送数据

  data:JSON.stringify({"Key":"value"}),
于 2013-09-28T13:59:11.200 回答