------前台JS
"<input class=\'jTabCheck2\' type=\'checkbox\' partvguid=" + obj + " projectvguid=" + projectVGUID + " reportvguid=" + reportVGUID + ">" //给CheckBox 添加三个自定义属性值
var partvguid = $("#input[type='checkbox']”).attr("partvguid");
var projectvguid = $("#input[type='checkbox']”).attr("projectvguid");
var reportvguid = $("#input[type='checkbox']”).attr("reportvguid");
//创建对象
var array = new Array();
var model = new Object();
model.partvguid = partvguid;
model.projectvguid = projectvguid;
model.reportvguid = reportvguid;
array.push(model);
}
var list = JSON.stringify(array);
$.ajax({
type: "post",
data: { "list": list },
url: "/Completed_Report/SubmitData",
success: function (msg) {
debugger;
if (msg.isSuccess == true || msg.isSuccess == "True" || msg.isSuccess == "true") {
$.jBox.tip(msg.respnseInfo);
$$$.bindDataList();
} else {
$.jBox.tip(msg.respnseInfo);
}
}, error: function (msg) {
console.log(msg);
}
})
----------C#后端获取
//控制器
[HttpPost]
public JsonResult SubmitData(string list)
{
ActionResultModel<string> result = new ActionResultModel<string>();
List<ReportInfo> dataList;
dataList = JSONToData.JsonToModel<List<ReportInfo>>(list);
string partList = "";
for (int i = 0; i < dataList.Count();i++ )
{
partList += dataList[i].partvguid.ToString();
}
List<Guid> vguidLists = SmartLabExtends.ToGuidList(partList);
bool flag = reportService.ValidateData(vguidLists);
if (flag)
{
string msg = reportService.SubmitData(dataList);
if (msg== "1")
{
result.isSuccess = true;
result.respnseInfo = "Submit Success";
}
else
{
result.isSuccess = false;
result.respnseInfo = "Submit Failed";
}
}
else
{
result.isSuccess = false;
result.respnseInfo = "The record status can not submit";
}
return Json(result);
}
//拓展类
public static class JSONToData
{
public static TEntity JsonToModel<TEntity>(this string json)
{
JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
jsSerializer.MaxJsonLength = Int32.MaxValue;
return jsSerializer.Deserialize<TEntity>(json);
}
}
//实体类
public class ReportInfo
{
public string partvguid { get; set; }
public string projectvguid { get; set; }
public string reportvguid { get; set; }
}