gpt4 book ai didi

c# - 发送动态表生成的 JSON 字符串时发布的空数据

转载 作者:太空宇宙 更新时间:2023-11-03 10:43:18 24 4
gpt4 key购买 nike

我正在我的 ASP.NET MVC 4 应用程序中动态生成一个表。该表的列中有输入框。我必须保存这些输入框中的数据。生成的表是enter image description here

点击上面的保存按钮,我从 jquery 中的表中读取数据

    var estimDetails = $('#editorRows tr:has(td)').map(function (i, v) {
var $td = $('td', this);
return {
ItemId: $($td[0]).find("select").val(),
Description: $($td[1]).find("input").val(),
Quantity: $($td[2]).find("input").val(),
Amount: $($td[3]).find("input").val()
}
}).get();
//Convert data to JSON
var estimateObject = JSON.stringify({ 'JsonString': estimDetails });
//post data to Controller Action
$.ajax({
type: 'POST',
url: '@Url.Action("SaveEstimate")',
data: estimateObject,
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function (data) {
if (data)
alert("Saved Successfully");
},
error: function (response) {
debugger;
alert(response);
}
});

检查“estimateObject”的值为
enter image description here

我的操作方法是

  [HttpPost]
public JsonResult SaveEstimate(string JsonString)
{
try
{
DateTime expDate;
DateTime expiryDt = new DateTime();


return Json("true", JsonRequestBehavior.AllowGet);
}
catch (Exception e)
{

return Json("false", JsonRequestBehavior.AllowGet);
}
}

但“JsonString”始终为空。我尝试了不同的方法,比如将字符串保存在 Controller 的 ViewModel 中,但没有帮助。请帮助我。

最佳答案

要么尝试这样做

 [HttpPost]
public JsonResult SaveEstimate(string id)
{
try
{
DateTime expDate;
DateTime expiryDt = new DateTime();


return Json("true", JsonRequestBehavior.AllowGet);
}
catch (Exception e)
{

return Json("false", JsonRequestBehavior.AllowGet);
}
}

或在 AJAX 调用中

$.ajax({
type: 'POST',
url: '@Url.Action("SaveEstimate")',
data: "JsonString=" + estimateObject,
dataType: 'json',
success: function (data) {
if (data)
alert("Saved Successfully");
},
error: function (response) {
debugger;
alert(response);
}
});

关于c# - 发送动态表生成的 JSON 字符串时发布的空数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24474602/

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