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>");
    }
    }
    }

  • 相关阅读:
    javascript设计模式(一)职责链模式China of responsibility
    javascript设计模式(一)策略模式Strategy
    angularjs提示消息弹出框
    Javascript设计模式(一)States
    Javascript设计模式(一)Facade
    NOIP2020
    RMQ & ST表
    NOI Linux
    初赛解析
    贪心大解析
  • 原文地址:https://www.cnblogs.com/htbmvc/p/7880873.html
Copyright © 2011-2022 走看看