Guest User

Untitled

a guest
Feb 7th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. @model List<ElencoCertificazioniItem>
  2. ...
  3.  
  4. @using (Html.BeginForm())
  5. {
  6. @Html.AntiForgeryToken()
  7. ...
  8. <tbody>
  9. @{
  10. for (int i = 0; i < Model.Count; i++)
  11. {
  12. <tr>
  13. <td>@Html.LabelFor(m => Model[i].Id) </td>
  14. <td>@Html.LabelFor(m => Model[i].description)</td>
  15. <td>@Html.EditorFor(m => Model[i].Field1.Value)</td>
  16. <td>@Html.EditorFor(m => Model[i].Field2.Value)</td>
  17. </tr>
  18. }
  19. }
  20. </tbody>
  21. }
  22. ....
  23.  
  24. [HttpPost]
  25. [ValidateAntiForgeryToken]
  26. [HttpParamAction]
  27. public ActionResult SaveItems(List<ElencoCertificazioniItem> model)
  28. {
  29. //the items here is null!!! ;(
  30. return saveItems(model);
  31. }
  32.  
  33. public class ElencoCertificazioniItem
  34. {
  35. public int Id { get; set; }
  36. public string description { get; set; }
  37. public bool? Field1 { get; set; }
  38. public bool? Field2 { get; set; }
  39.  
  40. }
  41.  
  42. public class HttpParamActionAttribute : ActionNameSelectorAttribute
  43. {
  44. public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo)
  45. {
  46. if (actionName.Equals(methodInfo.Name, StringComparison.InvariantCultureIgnoreCase))
  47. return true;
  48.  
  49. var request = controllerContext.RequestContext.HttpContext.Request;
  50. return request[methodInfo.Name] != null;
  51. }
  52. }
  53.  
  54. <tr>
  55. <td>
  56. @Html.LabelFor(m => Model[i].Id)
  57. @Html.HiddenFor(m => Model[i].Id)
  58. </td>
  59. <td>
  60. @Html.LabelFor(m => Model[i].description)
  61. @Html.HiddenFor(m => Model[i].description)
  62. </td>
  63. <td>@Html.EditorFor(m => Model[i].Field1)</td>
  64. <td>@Html.EditorFor(m => Model[i].Field2)</td>
  65. </tr>
Add Comment
Please, Sign In to add comment