[英]How to send model binded to view from ajax call on button click to controller action?
这是我的ajax电话:
$('#addNominationForm').on("submit", function (e) {
debugger;
e.preventDefault();
$.ajax({
type: 'post',
url: '@Url.Action("AddNomination", "Nomination")',
data: JSON.stringify({ model: model, submit: "submit" }),
contentType: "application/json; charset=utf-8",
success: function (data) {
swal({
title: "Nominated Successfully",
showCancelButton: false,
confirmButtonColor: "#88a364",
confirmButtonText: "Ok"
},
function () {
if (isConfirm) {
window.location.href = '@Url.Action("Dashboard", "Dashboard")';
}
});
},
Error: function (xhr, status, error) {
alert("error" + xhr.responseText)
}
});
});
这是动作:
[HttpPost]
[CustomeAuthorize(AllowedRole = "Manager")]
public ActionResult AddNomination(NominationViewModel model, string submit)
{
//business logic in action
}
但是在这里,当ajax调用完成时,实际模型中将包含null。 我该怎么办?或者还有其他方法可以通过在普通按钮单击时使用ajax调用在视图上发送模型吗?
不要对您的数据进行分类:
data: { model: model, submit: "submit" }
POST的主体为JSON(在这种情况下)
GET可以从查询字符串中获取数据,因此您需要在其中进行字符串化
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.