In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to edit and delete Asp.Mvc 2.0 users". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to edit and delete Asp.Mvc 2.0 users".
1. Show all users
We query all the user information and display it on the page in tabular form. The results are as follows:
First, all the user information is displayed on the index page. Find the controller corresponding to the index page, then find out all the user information, and put the set of users found in the viewdata.
Controller Code:
Public ActionResult Index () {/ / query out all users DataSet ds = new Models.SqlHelper (). GetAllUsers (); if (dswatches _ blank _ blank _ tables [0] .Rows.Count > 0) {List lists = new List (); for (int I = 0; I)
< ds.Tables[0].Rows.Count; i++) { Models.UserModels model = new Models.UserModels(); model.UserName = ds.Tables[0].Rows[i]["UserName"].ToString(); model.UserPwd = ds.Tables[0].Rows[i]["UserPwd"].ToString(); model.Email = ds.Tables[0].Rows[i]["Email"].ToString(); lists.Add(model); } if (lists.Count>0) {ViewData ["users"] = lists;}} return View ();}
Index page code
Username, password, mailbox edit, delete edit
Click the edit button after each row of data to go to the edit page. Next, let's look at the editing page.
two。 Edit user
First of all, let's take a look at the effect picture of the editing page.
Click the edit link for each line and go to the edit page to display the current user information.
First, let's take a look at the controller corresponding to the editing page:
/ go to the editing page / public ActionResult EditUser (string userName) {/ / get user information based on user name DataSet ds = new Models.SqlHelper () .GetSingleUser (userName) If (ds! = null & & ds.Tables [0] .Rows.Count > 0) {ViewData ["username"] = ds.Tables [0] .Rows [0] ["username"] .ToString (); ViewData ["userPwd"] = ds.Tables [0] .Rows [0] ["userpwd"] .ToString (); ViewData ["email"] = ds.Tables [0] .Rows [0] ["email"]. ToString () Return View ("edituser");} else {return View ("error");}}
Then the user information is displayed on the page, and in this place we display the page information using viewdata.
Page code
Modify user information user name: password: Mailbox:
Submit modification information
After modifying the user information on the editing page, click the submit button, and the user information will be submitted.
Let's take a look at the corresponding controller submitted.
[HttpPost] public ActionResult EditUser () {string userName = Request.QueryString ["UserName"] .ToString (); string userPwd = Request.Form ["txtUserPwd"] .ToString (); string email = Request.Form ["txtemail"] .ToString (); if (userName = "| userPwd = =") {ViewData ["errMsg"] = "username and password cannot be empty"; return EditUser (userName) } else {/ / Update the database bool result=new Models.SqlHelper () .UpdateUser (userName, userPwd, email); if (result) {/ / go to the home page DataSet ds = new Models.SqlHelper () .GetAllUsers () If (ds! = null & & ds.Tables [0] .Rows.Count > 0) {List lists = new List (); for (int I = 0; I
< ds.Tables[0].Rows.Count; i++) { Models.UserModels model = new Models.UserModels(); model.UserName = ds.Tables[0].Rows[i]["UserName"].ToString(); model.UserPwd = ds.Tables[0].Rows[i]["UserPwd"].ToString(); model.Email = ds.Tables[0].Rows[i]["Email"].ToString(); lists.Add(model); } if (lists.Count >0) {ViewData ["users"] = lists;}} return View ("index");} else {ViewData ["errMsg"] = "update failed"; return EditUser (userName);}}
In submitting the controller, we use Request.Form to get what the user typed. After the submission is successful, go to the INDEX home page.
3. Delete the user.
Click the delete link and the corresponding controller will be deleted based on the current user name.
/ public ActionResult DelUser (string userName) {bool result = new Models.SqlHelper () .DelUser (userName); DataSet ds = new Models.SqlHelper () .GetAllUsers (); if (ds! = null & & ds.Tables [0] .Rows.Count > 0) {List lists = new List () For (int I = 0; I
< ds.Tables[0].Rows.Count; i++) { Models.UserModels model = new Models.UserModels(); model.UserName = ds.Tables[0].Rows[i]["UserName"].ToString(); model.UserPwd = ds.Tables[0].Rows[i]["UserPwd"].ToString(); model.Email = ds.Tables[0].Rows[i]["Email"].ToString(); lists.Add(model); } if (lists.Count >0) {ViewData ["users"] = lists;}} return View ("index") Thank you for reading, the above is the content of "how to edit and delete Asp.Mvc 2.0 users". After the study of this article, I believe you have a deeper understanding of how to achieve the editing and deletion of Asp.Mvc 2.0 users, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.