Guest User

Untitled

a guest
Feb 13th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. public ActionResult Admin(uint id, FormCollection collection) {
  2. var username = collection.Get("username");
  3. var password = collection.Get("password");
  4. Helper.CreateUser(username,password);
  5. return View("AdministerUsers");
  6. }
  7.  
  8. <% using (Html.BeginForm()){ %>
  9. <fieldset>
  10. <legend>Fields</legend>
  11. <label for="username">username</label>
  12. <%= Html.TextBox("username") %>
  13. <label for="password">password:</label>
  14. <%= Html.TextBox("password") %>
  15. </fieldset>
  16. <input type="submit" value="Add User" name="submitUser" />
  17. <% } %>
  18.  
  19. routes.MapRoute(
  20. "Admin",
  21. "Admin/{id}",
  22. new { controller = "Administration", action = "Admin"}
  23. );
  24.  
  25. public class ViewModel
  26. {
  27. public string Username {get; set;}
  28. public string Password {get; set;}
  29. }
  30.  
  31. <%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<ViewModel>" %> //the ViewModel will need to have it's fully qualified name here
  32.  
  33. <% using (Html.BeginForm()){ %>
  34.  
  35. <%= Html.LabelFor(m => m.Username) %>
  36. <%= Html.TextBoxFor(m => m.Username) %>
  37.  
  38. <%= Html.Label(m => m.Password) %>
  39. <%= Html.TextBoxFor(m => m.Password) %>
  40.  
  41. <input type="submit" value="Add User" name="submitUser" />
  42. <% } %>
  43.  
  44. [HttpPost]
  45. public ActionResult Admin(ViewModel model)
  46. {
  47. var username = model.Username;
  48. var password = model.Password;
  49. Helper.CreateUser(username,password);
  50. return View("AdministerUsers");
  51. }
  52.  
  53. public ActionResult Admin(uint id, string username, string password)
  54. {
  55. // .. Do your stuff
  56. }
Add Comment
Please, Sign In to add comment