C# MVC ajax将json传到后台接口

前台:

   //保存数据
        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!");
            }); 
        }

后台:

 /// 
        /// 保存check信息
        /// Author:LYB
        /// Date:2023年7月14日 10:24:32
        /// 
        /// 
        /// 
        [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(json);
            //判断主键内容是否为空, 为空新增, 有值修改
            if (jo.SelectToken("Entity") == null)
            {
                result.success = false;
                result.msg = "缺少 Entity 参数!";
                return Json(result);
            }

          
            //参数转实体
            PR_OperationInspectItemEntity entity = JsonConvert.DeserializeObject(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,c#,mvc,ajax)