MVC Basic Operations

Source: Internet
Author: User

        #region Home public ActionResult Index () {String user_test_select = "User_test_select";            var item = dbhelp.getlist<test_model> (User_test_select);        return View (item);        } #endregion #region Add public actionresult Create () {return View ();            } #region Post value [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 Modify 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 value [httppost] public actionresult Edit (Models.test_model model) {string USER_UPD            ate = "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 pass value delete [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 Basic Operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.