前台:文章来源:https://www.toymoban.com/news/detail-564986.html
//保存数据
function PostRowData(rowData) {
let postData = { "Entity": rowData };
console.log("These data will be saved:---------------------- ", JSON.stringify(postData));
$.post("/Quality/SaveOperationInspectItemResult", { "json": JSON.stringify(postData) }, function (data) {
console.log("Result:------------ Row data save success!");
});
}
后台:文章来源地址https://www.toymoban.com/news/detail-564986.html
/// <summary>
/// 保存check信息
/// Author:LYB
/// Date:2023年7月14日 10:24:32
/// </summary>
/// <param name="json"></param>
/// <returns></returns>
[HttpPost]
public JsonResult SaveOperationInspectItemResult(string json)
{
var result = new ResponseResult();
result.code = 1;
string msg = "";
QualityBLL bll = new QualityBLL();
if (string.IsNullOrEmpty(json))
{
result.success = false;
result.msg = "参数不能为空!";
return Json(result);
}
JObject jo = JsonConvert.DeserializeObject<JObject>(json);
//判断主键内容是否为空, 为空新增, 有值修改
if (jo.SelectToken("Entity") == null)
{
result.success = false;
result.msg = "缺少 Entity 参数!";
return Json(result);
}
//参数转实体
PR_OperationInspectItemEntity entity = JsonConvert.DeserializeObject<PR_OperationInspectItemEntity>(CommonFunction.getValue(jo, "Entity"));
if (string.IsNullOrEmpty (entity.Id.ToString()))
{
result.success = false;
result.msg = "缺少 Id 参数!";
return Json(result);
}
if (string.IsNullOrEmpty(entity.Operation_Id.ToString()))
{
result.success = false;
result.msg = "缺少 Operation_Id参数!";
return Json(result);
}
var b = bll.SaveOperationInspectItemResult(entity, out msg);
result.code = b == true ? 0 : 1;
result.success = b;
result.msg = msg;
return Json(result);
}
到了这里,关于C# MVC ajax将json传到后台接口的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!