#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