Advertisement
Guest User

Untitled

a guest
Sep 15th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. <form action="/home/showdata" method="post">
  2. <input type="text" name="arr.username" />
  3. <input type="text" name="arr.password" />
  4. <input type="text" name="arr.email" />
  5. </form>
  6.  
  7. public class HomeController : Controller
  8. {
  9. [HttpPost]
  10. public ActionResult ShowData(Array data)
  11. {
  12. return Content(data.username + data.password + data.email);
  13. }
  14. }
  15.  
  16. public ActionResult ShowData(Array data)
  17.  
  18. public ActionResult ShowData(YourModelNameHere data)
  19.  
  20. public class YourModelNameHere
  21. {
  22. public string username {get; set;}
  23. public string password {get; set;}
  24. public string email {get; set;}
  25. }
  26.  
  27. <form action="/home/showdata" method="post">
  28. <input type="text" name="username" />
  29. <input type="text" name="password" />
  30. <input type="text" name="email" />
  31. </form>
  32.  
  33. public class HomeController : Controller
  34. {
  35.  
  36. [HttpPost]
  37. public ActionResult ShowData(FormCollection data)
  38. {
  39. string username=data.GetValues("username")[0];
  40. string password=data.GetValues("password")[0];
  41. string email=data.GetValues("email")[0];
  42.  
  43. return Content(username + password + email);
  44. }
  45. }
  46.  
  47. public class SampleViewModel {
  48. public int Id { get; set;}
  49. public string Name { get; set; }
  50. }
  51.  
  52. public IHttpActionResult SampleActionMethod(SampleViewModel model) {
  53. if (!ModelState.IsValid) {
  54. return BadRequest();
  55. }
  56. var sampleDbModel = new SampleDatabaseModel() {
  57. FullName = model.Name,
  58. ProductId = model.Id,
  59. // ... some other properties ...
  60. };
  61. // ... Save the sampleDbModel ...
  62. return Ok(); // .. or Created ...
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement