我正在尝试将一个参数从我的视图传递给我的控制器,我遇到: 当我尝试执行我的操作GetCompanyDataWithId时,值不能为空。
成功运行会将参数传递给控制器,控制器将返回用于填充jqGrid的JSON数据。
似乎价值未正确传递 有什么想法吗?
$("#dropdwnlist").change(function () {
var value = $(this).val();
$.ajax({
url: '<%= Url.Action("GetCompanyDataWithId", "Billing") %>',
type: "POST",
data: { companyid: "25" },
success: function (data) {
alert(data);
$('#Bgrid').setGridParam({ url: '<%= Url.Action("GetCompanyDataWithId", "Billing") %>'});
$('#Bgrid').trigger('reloadGrid');
},
error: function(xhr, ajaxOptions, thrownError) {
alert(xhr.responseText);
}
}).done(function (msg) {
alert("Data Saved: " + msg);
});
});
答案 0 :(得分:1)
假设您的控制器方法如下:
public ActionResult GetCompanyDataWithId(string companyid) {}
您可以使用以下$.ajax
选项:
data: JSON.stringify({ companyid: "25" }),
type: 'post',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
或更简单:
Url.Action("GetCompanyDataWithId", "Billing", new { companyid = "25" })