Insert(新增)

作者:清晨

新增数据( 表单提交

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);
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值