• MVC 基本操作


            #region 首页
            public ActionResult Index()
            {
                string User_Test_Select = "User_Test_Select";
                var item = DBhelp.GetList<test_model>(User_Test_Select);
                return View(item);
            }
            #endregion
    
            #region 增加
            public ActionResult Create()
            {
                return View();
            }
            #region Post 传值
            [HttpPost]
            public ActionResult Create(Models.test_model model)
            {
                string User_Test_Add = "insert into Test (name,age) values('" + model.name + "'," + model.age + ")";
                int i = DBhelp.ExecuteSql(User_Test_Add);
                if (i > 0)
                {
                    return RedirectToAction("Index");
                }
                else
                {
                    return View();
                }
            }
            #endregion
            #endregion
    
            #region 修改
            public ActionResult Edit(int id)
            {
                SqlParameter[] parameters = {
                        new SqlParameter("@ID", SqlDbType.Int,4)
                        };
                parameters[0].Value = id;
                DataSet ds = DBhelp.RunProcedure("User_Test_Select_One", parameters, "test");
                test_model model = new test_model();
                if (ds.Tables[0].Rows.Count > 0)
                {
                    if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
                    {
                        model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                    }
                    if (ds.Tables[0].Rows[0]["name"] != null && ds.Tables[0].Rows[0]["name"].ToString() != "")
                    {
                        model.name = ds.Tables[0].Rows[0]["name"].ToString();
                    }
                    if (ds.Tables[0].Rows[0]["age"] != null && ds.Tables[0].Rows[0]["age"].ToString() != "")
                    {
                        model.age = int.Parse(ds.Tables[0].Rows[0]["age"].ToString());
                    }
                }
                return View(model);
            }
            #region post传值
            [HttpPost]
            public ActionResult Edit(Models.test_model model)
            {
                string User_Update = "Update Test set name='" + model.name + "' , age=" + model.age + "  where id=" + model.ID;
                int i = DBhelp.ExecuteSql(User_Update);
                if (i > 0)
                {
                    return RedirectToAction("Index");
                }
                else
                {
                    return View();
                }
            }
            #endregion
            #endregion
    
            #region get 传值删除
            [HttpGet]
            public ActionResult Delete(int id)
            {
                string User_Test_Delect = "delete Test where ID= " + id;
                int i = DBhelp.ExecuteSql(User_Test_Delect);
                string url = Request.UrlReferrer == null ? "UserTest/Index" : Request.UrlReferrer.ToString();
                if (i > 0)
                {
                    return Redirect(url);
                }
                else { return Redirect(url); }
            }
            #endregion
    

      

  • 相关阅读:
    小程序解析html(使用wxParse)
    error: the HTTP rewrite module requires the PCRE library
    CMake Error at cmake/boost.cmake:76 (MESSAGE)
    Centos7安装mysql后无法启动,提示 Unit mysql.service failed to load:No such file or directory
    mysql的三种安装方式
    epel源
    cmake
    yum
    wget
    tar指令
  • 原文地址:https://www.cnblogs.com/zhubaobao/p/3972856.html
Copyright © 2020-2023  润新知