zoukankan      html  css  js  c++  java
  • 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
    

      

  • 相关阅读:
    (一二二)核心动画进阶
    1089. Insert or Merge (25)
    (一二一)核心动画基础
    (一二〇)CALayer的一些特性
    (一一九)通过CALayer实现阴影、圆角、边框和3D变换
    1086. Tree Traversals Again (25)
    POJ 2610:Dog & Gopher
    模拟内存分配(链表实现)
    圣诞树后能找到我的记忆
    YTU 2797: 复仇者联盟之关灯
  • 原文地址:https://www.cnblogs.com/zhubaobao/p/3972856.html
Copyright © 2011-2022 走看看