I have two form in my view. One form searching records. One form for Goto page {number of page} to support pagination. As almost everyone suggested in similar question, I must create two separate action for every form. It will make my work very easy, but I have problem when using these approach.
Assume I have following model:
public class MyModel
{
public string Name { get; set; }
public string DateOfEmployment { get; set; }
public int? PageNumber { get; set; }
}
And following view:
@model WebApplication1.Models.MyModel
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { }))
{
@Html.LabelFor(m => m.DateOfEmployment)
@Html.EditorFor(m => m.DateOfEmployment)
@Html.LabelFor(m => m.Name)
@Html.TextBoxFor(m => m.Name)
<input type='Submit' value='Search' />
}
<!-- Rows goes here-->
@using (Html.BeginForm("Pagination", "Home", FormMethod.Post, new { }))
{
@Html.LabelFor(m => m.PageNumber)
@Html.TextBoxFor(m => m.PageNumber)
<input type='Submit' value='Go' />
}
The problem is when user click Go
button, how can I know that what is search field values to recreate model rows?. If I use single form, I don't know which button clicked (in a clean way). So what should I do in these situation?