作者:清晨
新增数据( 表单提交)
js视图
View的代码
function InsertSave{
//获取值
var oneID =$("#one").val();
var two =$("#two").val();
var three =$("#three").val();
var four =$("#four").val();
//判断条件是否为空
if(oneID>0&&two !=""&&three !=""&&four !="")"{
//用表单提交的方法一
$("#formAbnorma").ajaxSubmit(function (msg){
if(msg=="success"){
layer.confirm("新增成功是否进行下一步",{
icon:3,//按钮,样式
btn:['确定','取消']},function(layerIndex){
//关闭加载层
layer.close(layerIndex);
//刷新表格
tbTable.refreshPage();
alert("确认成功"});
})
}else{
alert("确认失败");
}
});
//方法二(用键值对的方法来传递参数的)
// $.post("InsertAbnorma",
// { oneID:oneID,
// two:two,
// three:three,
// four:four,
// },function(data){
// if(data=="success"){
// alert("新增成功");
// tbTable.refreshPage();//刷新表格
// }else{
// alert("新增失败");
// }
// });
}esle{
alert("请填写完整数据");
}
控制器
public ActionResult InsertAbnorma(fromAbnorma from)
{
//声明strMsg
string strMsg = "";
pw_Abnorma Abnorma=new pw_Abnorma();
Abnorma.oneID=Convert.ToInt32(from["oneID"]);
Abnorma.two=from["two"];
Abnorma.three=from["three"];
Abnorma.four=from["four"];
//复选框
if(from["Bit"]==null){
Abnorma.Bit==false;
}else if(from ["Bit"]=="on"){
Abnorma.Bit==true;
}
//添加到表中
myModel.pw_Abnorma.Add(Abnorma);
if(myModel.SaveChages()>0){
strMsg=="success";
}
return Json(strMsg, JsonRequestBehavior.AllowGet);
}