MVC 基本操作

來源:互聯網
上載者:User

標籤:blog   http   io   os   ar   div   cti   log   on   

        #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

  

MVC 基本操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.