zoukankan      html  css  js  c++  java
  • 修改MVCfrom表单

    [HttpGet]
    public ActionResult xiugai(int id=0)
    {

    var checkedlist = new List<checklist>() {
    new checklist(){ id =1, name ="打球"},
    new checklist(){ id =2, name ="唱歌"},
    new checklist (){ id=3, name="唱戏"},
    new checklist(){ id =4, name="敲代码"}
    };
    ViewBag.che = checkedlist;

    var m = new BLL.studentbll().getdatatable().Find(T => T.id == id);
    var model = new studentM
    {
    id = id,
    age = m.age,
    aihao = m.aihao,
    homeid = m.homeid,
    img = m.img,
    name = m.name,
    sex = m.sex,
    shijian = m.shijian
    };
    var result = new BLL.homebll().getdatatble();
    SelectList list = new SelectList(result, "homeid", "homename");
    ViewBag.list = list;
    return View(model);
    }
    [HttpPost]
    public ActionResult xiugai(studentM m)
    {
    var bql = Request.Form["aihao"];
    //获取图片的字段
    var file = Request.Files["newImg"];

    if (file.FileName != "")
    {
    //获取图片的路径
    var filepath = "/Content/img/" + file.FileName;
    //转化为虚拟路径
    file.SaveAs(Server.MapPath(filepath));
    //转化三层的数据
    var model = new studentmodel
    {
    id = m.id,
    img = filepath,
    shijian = m.shijian,
    aihao = bql,
    homeid = m.homeid,
    age = m.age,
    sex = m.sex,
    name = m.name
    };
    //接受bll层的方法
    var result = new BLL.studentbll().xiugai(model);
    if (result > 0)
    {
    return Content("<script>alert('修改成功');location.href='/student/Index'</script>");
    }
    else
    {
    return Content("<script>alert('修改失败');</script>");
    }
    }
    else
    {
    var model = new studentmodel
    {
    id = m.id,
    img = m.img,
    shijian = m.shijian,
    aihao = bql,
    homeid = m.homeid,
    age = m.age,
    sex = m.sex,
    name = m.name
    };
    //接受bll层的方法
    var result = new BLL.studentbll().xiugai(model);
    if (result > 0)
    {
    return Content("<script>alert('修改成功');location.href='/student/Index'</script>");
    }
    else
    {
    return Content("<script>alert('修改失败');</script>");
    }
    }
    }

  • 相关阅读:
    sosex !mk
    使用boost iostream写文件
    编译ios版本的ffmpeg0.11.1
    转换日期为中文数字
    sosex !muf查看方法的反汇编代码
    Xcode 4.5.2 + iOS 6.0免证书(iDP)开发+真机调试+生成IPA全攻略
    sosex查看变量的命令!mdt
    vs2012编译openssl
    为ios编译openssl
    打开的页面关闭后刷新主页面
  • 原文地址:https://www.cnblogs.com/htbmvc/p/7880873.html
Copyright © 2011-2022 走看看