问题描述
我在$ {document)中有这个jquery脚本。准备将数据发布到我的数据库中
$('#btnSaveStatus').on('click',function () {
//$('#btnSumitChanges').click()
var stid = $('#StoreID').val()
var oStid = $('#oldStatus').val()
var ddlID = $('#ddlStatusDef').val()
var strUrl = $('#txtUrl').val()
debugger;
if (oStid != ddlID) {
$.ajax({
url: strUrl,type: 'POST',contentType: 'apllication/html; charset=utf-8',data:{'sToreid': stid,'StatusDefid': ddlID},dataType: 'html',success: function (result) {
$('#Divstatus').modal('hide');
}
})
}
这是我的动作
public ActionResult ChangeStoreStatus(string sToreid,string StatusDefid)
{
} 即使在脚本中正确发送了值,在动作方法中sToreid和StatusDefid也为null。他们没有收到 有人可以帮我找出问题所在吗?
致谢
解决方法
根据文档,选项contentType
用于发送到服务器的数据。您没有发送html。只需删除该声明并允许使用默认的'application / x-www-form-urlencoded; charset = UTF-8'。
所有设置都是可选的。
...
contentType (默认:'application / x-www-form-urlencoded; charset = UTF-8')
类型:布尔值或字符串
将数据发送到服务器时,请使用此内容类型。默认 是“ application / x-www-form-urlencoded; charset = UTF-8”,可以 在大多数情况下。 ...-https://api.jquery.com/jQuery.ajax/