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

  • 相关阅读:
    JS字符串截取(获取指定字符后面的所有字符内容)
    vue图片上传插件
    php获取两个日期之间的所有日期
    laravel做定时任务时,加参数(也可缓存参数)
    前端传参数(数组,值为json字符串),后端接收json_decode()转为数组,数组为空值
    springboot的maven多模块项目
    如何给文件重命名
    springboot的get请求和post请求
    java调用ffmpeg
    mybatis批量插入List
  • 原文地址:https://www.cnblogs.com/htbmvc/p/7880873.html
Copyright © 2011-2022 走看看