gpt4 book ai didi

c# - ajax 调用后 Controller 中的 Formcollection 输入值为空

转载 作者:行者123 更新时间:2023-11-28 08:23:50 25 4
gpt4 key购买 nike

我在使用 IE 和 FF 时遇到了问题;我的应用程序正在与 Google Chrome 配合使用。

我正在将模型绑定(bind)到 ASP.NET MVC 中的 View 我在表单(和其他一些控件)中有一个表行。我用 ajax 调用替换了单击按钮时表行的内容。 ajax 调用后,如果我提交如下所示的表单,我无法从 Controller 方法获取 formcollection 输入。我在ajax调用之前提交表单没有问题。

更新表格行内容的js代码:

function reloadCriteriaTable(unitID, criteriaCode, icerikRowSpan, icerikOnay) {
$.ajax({
type: "GET",
url: 'ApproveParts/ReloadCriteria',
data: { contentID: $('[name="contentID"]').val(), unitID: unitID, criteriaCode: criteriaCode, selectedValue: $("#validator_" + criteriaCode).val(), icerikRowSpan: icerikRowSpan, icerikOnay: icerikOnay },
cache: false,
type: "POST",
success: function (data, textStatus, XMLHttpRequest) {
$('#tr_' + criteriaCode).replaceWith(data);
$('#continueBtn').on('click', function () {
$('#form_3').submit();
return false;
});
},
error: function (xhr, status, error) {
alert(xhr + ' ' + status + " : " + error);
}

});
}

Onclick函数:

$(document).on("click", ".btnSubmitCriteria", function () {
$('#form_3').submit();
return false;
});

Controller 方法:

[HttpPost]
public ActionResult CourseCriteriaApprovment(FormCollection collection)
{

}

最佳答案

首先要说明为什么您在 ajax 调用中同时提到了“GET”和“POST”类型。仅使用“POST”。

试试这个

$.ajax({
type: 'POST',
url: '/ApproveParts/ReloadCriteria',
dataType: 'json',
contentType: 'application/json',
data : return JSON.stringify({
contentID: $('[name="contentID"]').val(),
unitID: unitID,
criteriaCode: criteriaCode,
selectedValue: $("#validator_" + criteriaCode).val(),
icerikRowSpan: icerikRowSpan,
icerikOnay: icerikOnay
});
});

在您的 Controller 操作中接受一个类而不是 FormCollection。该类的所有属性定义与您在 ajax 调用中发送的属性相同。

关于c# - ajax 调用后 Controller 中的 Formcollection 输入值为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22662307/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com