Guest User

Untitled

a guest
Nov 24th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. public class PersonController : Controller {
  2. public ActionResult Buscar(int id)
  3. {
  4. var mm = DataBase.getById(id);
  5. return View(mm);
  6. }
  7. }
  8.  
  9. public class DataBase
  10. {
  11. private static List<Person> people = new List<Person>();
  12. private static int _nextId = 1;
  13. public static List<Person> getAll() {
  14. return people;}
  15. public static Person getById(int id)
  16. {
  17. var buscar = people.Find(x => x.Id == id);
  18. if (buscar == null)
  19. {
  20. throw new ArgumentNullException("id");
  21. }
  22. return buscar;}
  23.  
  24. @using (Html.BeginForm("Buscar", "Person",FormMethod.Get))
  25. {
  26. <form>
  27. Title: @Html.TextBox("id");
  28. <input type="submit"
  29. name="name"value="Buscar"/>
  30. </form>
  31. }
  32. <p>@Html.ActionLink("Create New",
  33. "Create")
  34. </p>
  35. <table class="table">
  36. <tr>
  37. <th>
  38. @Html.DisplayNameFor(model => model.Id)
  39. </th>
  40. <th>@Html.DisplayNameFor(model =>
  41. model.Name)
  42. </th>
  43. <th>@Html.DisplayNameFor(model =>
  44. model.Age)
  45. </th>
  46. <th>
  47. @Html.DisplayNameFor(model => model.Street)
  48. </th>
  49. <th>
  50. @Html.DisplayNameFor(model => model.City)
  51. </th>
  52. <th>
  53. @Html.DisplayNameFor(model => model.State)
  54. </th>
  55. <th>
  56. @Html.DisplayNameFor(model => model.Zipcode)
  57. </th>
  58. <th></th>
  59. </tr>
  60.  
  61. @foreach (var item in Model)
  62. {
  63. <tr>
  64. <td>
  65. @Html.DisplayFor(modelItem => item.Id)
  66. </td>
  67. <td>
  68. @Html.DisplayFor(modelItem => item.Name)
  69. </td>
  70. <td>
  71. @Html.DisplayFor(modelItem => item.Age)
  72. </td>
  73. <td>
  74. @Html.DisplayFor(modelItem => item.Street)
  75. </td>
  76. <td>
  77. @Html.DisplayFor(modelItem => item.City)
  78. </td>
  79. <td>
  80. @Html.DisplayFor(modelItem => item.State)
  81. </td>
  82. <td>
  83. @Html.DisplayFor(modelItem => item.Zipcode)
  84. </td>
  85. <td>
  86. @Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
  87. @Html.ActionLink("Details", "Details", new { id = item.Id }) |
  88. @Html.ActionLink("Delete", "Delete", new { id = item.Id })
  89. </td>
  90. </tr>
  91. }
  92.  
  93. public class RouteConfig
  94. {
  95. public static void RegisterRoutes(RouteCollection routes)
  96. {
  97. routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  98.  
  99. routes.MapRoute(
  100. name: "Default",
  101. url: "{controller}/{action}/{id}",
  102. defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
  103. );
  104. }
  105. }
  106.  
  107. @using (Html.BeginForm("Buscar", "Person",FormMethod.Post))
  108. {
  109.  
  110. Title: @Html.TextBox("id");
  111. <input type="submit" name="name"value="Buscar"/>
  112.  
  113. }
  114.  
  115. @using (Html.BeginForm("xx", "Person", FormMethod.Post))
  116. {
  117. <p>@Html.ActionLink("Create New", "Create")
  118. </p>
  119. <table class="table">
  120. <tr>
  121. <th>
  122. @Html.DisplayNameFor(model => model.Id)
  123. </th>
  124. <th>@Html.DisplayNameFor(model =>
  125. model.Name)
  126. </th>
  127. <th>@Html.DisplayNameFor(model =>
  128. model.Age)
  129. </th>
  130. <th>
  131. @Html.DisplayNameFor(model => model.Street)
  132. </th>
  133. <th>
  134. @Html.DisplayNameFor(model => model.City)
  135. </th>
  136. <th>
  137. @Html.DisplayNameFor(model => model.State)
  138. </th>
  139. <th>
  140. @Html.DisplayNameFor(model => model.Zipcode)
  141. </th>
  142. <th></th>
  143. </tr>
  144.  
  145. @foreach (var item in Model)
  146. {
  147. <tr>
  148. <td>
  149. @Html.DisplayFor(modelItem => item.Id)
  150. </td>
  151. <td>
  152. @Html.DisplayFor(modelItem => item.Name)
  153. </td>
  154. <td>
  155. @Html.DisplayFor(modelItem => item.Age)
  156. </td>
  157. <td>
  158. @Html.DisplayFor(modelItem => item.Street)
  159. </td>
  160. <td>
  161. @Html.DisplayFor(modelItem => item.City)
  162. </td>
  163. <td>
  164. @Html.DisplayFor(modelItem => item.State)
  165. </td>
  166. <td>
  167. @Html.DisplayFor(modelItem => item.Zipcode)
  168. </td>
  169. <td>
  170. @Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
  171. @Html.ActionLink("Details", "Details", new { id = item.Id }) |
  172. @Html.ActionLink("Delete", "Delete", new { id = item.Id })
  173. </td>
  174. </tr>
  175. }
  176. }
  177.  
  178. public class PersonController : Controller {
  179.  
  180. [HttpPost]
  181. public ActionResult Buscar(int id)
  182. {
  183. var mm = DataBase.getById(id);
  184. return View(mm);
  185. }
  186.  
  187. }
Add Comment
Please, Sign In to add comment