网站中如果遇到批量提交格式相同数据,可以使用json来传输
$("#catalogSave").click(function(){
var array=[];
$("[name=checkCatalog]:checked").each(function(i,u){
var CatalogID=$(u).val();
var DisplayName=$(u).attr("tag");
array.push('{"CatalogID":"'+CatalogID+'","DisplayName":"'+DisplayName+'"}');
});
$.post("/GoWhere/AddCatalog",{str:"["+array.join(",")+"]"},function(msg){
if(msg=="ok"){
alert("编辑成功");
window.location.href="/GoWhere/GoWhereIndexLogin";
}else{
alert("编辑失败");
}
},"text");
});
后台接收:
public ActionResult AddCatalog(string str) { List<CatalogCustom> list = SerializeHelper.DeserializeFromJson<List<CatalogCustom>>(str); int uid = SystemManager.GetUID(this.Request); int flag = GoWhereList.Instance.EditorProductUserLovesByUid(uid, list); if (flag > 0) { return this.Content("ok"); } else { return this.Content("error"); } }
博客重点是拼json对象的样式(这个千万不能错)
“确定”按钮没在图中