Ritendra Mall

Ritendra Mall

  • NA
  • 316
  • 31.1k

How to pass data from view to controller using model binding

Aug 21 2019 1:18 AM
Hello,
 
Please help to understand how pass view values to controller as parameters on clicking of filter button below is my code sample
 
View
  1. @model UniPro.Web.Models.EmployeeDashboardModel  
  2. @{  
  3. ViewBag.Title = "EmployeeList";  
  4. Layout = "~/Views/Shared/_Layout.cshtml";  
  5. }  
  6. <h2>LocationList</h2>  
  7. @using (Html.BeginForm("filterLOV""EmployeeLocationList", FormMethod.Get))  
  8. {  
  9. <div class="contentbox">  
  10. <p class="contentboxheading">  
  11. @ViewBag.Title  
  12. </p>  
  13. <div class="contentbox_innercontent">  
  14. <table width="100%">  
  15. <tr>  
  16. <td >  
  17. @Html.Hidden("ID",Model.EmpListLOV,new { id = "empID"})  
  18. <label class="highlightlabel">ID</label>  
  19. </td>  
  20. <td >  
  21. @Html.DevExpress().TextBox(  
  22. txtsetting =>  
  23. {  
  24. txtsetting.Name = "txtemployeeID";  
  25. txtsetting.ClientEnabled = true;  
  26. txtsetting.Width = System.Web.UI.WebControls.Unit.Pixel(150);  
  27. txtsetting.Height = System.Web.UI.WebControls.Unit.Pixel(25);  
  28. txtsetting.Properties.MaxLength = 50;  
  29. ().value); }";  
  30. }).GetHtml()  
  31. </td>  
  32. <td >  
  33. <label class="highlightlabel">Name</label>  
  34. </td>  
  35. <td >  
  36. @Html.Hidden("Name", Model.EmpListLOV, new { id = "hiddenName" })  
  37. @Html.DevExpress().TextBox(  
  38. txtsetting =>  
  39. {  
  40. txtsetting.Name = "txtemployeeName";  
  41. txtsetting.ClientEnabled = true;  
  42. txtsetting.Width = System.Web.UI.WebControls.Unit.Pixel(150);  
  43. txtsetting.Height = System.Web.UI.WebControls.Unit.Pixel(25);  
  44. txtsetting.Properties.MaxLength = 50;  
  45. }).GetHtml()  
  46. </td>  
  47. <td >  
  48. <label class="highlightlabel">Age</label>  
  49. </td>  
  50. <td >  
  51. @Html.Hidden("Age", Model.EmpListLOV, new { id = "hiddenAge" })  
  52. @Html.DevExpress().TextBox(  
  53. txtsetting =>  
  54. {  
  55. txtsetting.Name = "txtemployeeAge";  
  56. txtsetting.ClientEnabled = true;  
  57. txtsetting.Width = System.Web.UI.WebControls.Unit.Pixel(150);  
  58. txtsetting.Height = System.Web.UI.WebControls.Unit.Pixel(25);  
  59. txtsetting.Properties.MaxLength = 50;  
  60. }).GetHtml()  
  61. </td>  
  62. <td >  
  63. <label class="highlightlabel">Maritial Status</label>  
  64. </td>  
  65. <td >  
  66. @Html.Hidden("EMPMaritial_Status", Model.maritial_StatusList, new { id = "hiddenstatus" })  
  67. @Html.DevExpress().ComboBox(  
  68. settings =>  
  69. {  
  70. settings.Name = "drostatus";  
  71. settings.Width = System.Web.UI.WebControls.Unit.Pixel(100);  
  72. //settings.Style.Add("width", "85");  
  73. settings.Properties.DropDownStyle = DevExpress.Web.ASPxEditors.DropDownStyle.DropDownList;  
  74. settings.Properties.TextFormatString = "{0}";  
  75. settings.Properties.ValueType = typeof(string);  
  76. settings.Properties.ValueField = "ID";  
  77. settings.Properties.TextField = "EMPMaritial_Status";  
  78. }).BindList(Model.maritial_StatusList).GetHtml()  
  79. <td >  
  80. <label class="highlightlabel">Location</label>  
  81. </td>  
  82. <td >  
  83. @Html.Hidden("EMP_Location", Model.LocationLOV, new { id = "hiddenLocation" })  
  84. @Html.DevExpress().ComboBox(  
  85. settings =>  
  86. {  
  87. settings.Name = "droLocation";  
  88. settings.Width = System.Web.UI.WebControls.Unit.Pixel(100);  
  89. //settings.Style.Add("width", "85");  
  90. settings.Properties.DropDownStyle = DevExpress.Web.ASPxEditors.DropDownStyle.DropDownList;  
  91. settings.Properties.TextFormatString = "{0}";  
  92. settings.Properties.ValueType = typeof(string);  
  93. settings.Properties.ValueField = "ID";  
  94. settings.Properties.TextField = "EMP_Location";  
  95. }).BindList(Model.LocationLOV).GetHtml()  
  96. </td>  
  97. <td >  
  98. <input type="button" name="btnSearch" id="btnFilter" value="Apply Filter" class="buttoncss" title="Click for Search" style="width: 100px;" />  
  99. </td>  
  100. </tr>  
  101. </table>  
  102. </div>  
  103. <div align="center" style="margin-top:3%" id="container">  
  104. @Html.Partial("EmplyeeDemoGridPartial", Model.EmpListLOV)  
  105. </div>  
  106. </div>  
  107. }  
controller
  1. public ActionResult FilterLOV(int? txtemployeeID, string txtemployeeName, int? txtemployeeAge,int? droLocation)  
  2. {  
  3. List<EmployeeDemoObjectDomain> empSearch = new List<EmployeeDemoObjectDomain>();  
  4. IEmployeeDemoBusinessService empSearchBS = new EmployeeDemoBusinessService();  
  5. empSearch = empSearchBS.GetEmployeeByFilter(txtemployeeID, txtemployeeName,txtemployeeAge, droLocation);  
  6. return PartialView("EmplyeeDemoGridPartial", empSearch);  
  7. }  
Model
  1. public class EmployeeDashboardModel  
  2. {  
  3. public List<EmployeeDemoObjectDomain> EmpListLOV { getset; }  
  4. public List<LocationLOV> LocationLOV{get;set;}  
  5. public List<Maritial_StatusDemoList> maritial_StatusList { getset; }  
  6. }  
Firstly i was using ajax call to pass the data from the view to controller but i want to do the same with model binding.
 
Please suggest.

Answers (2)