I have a table with loads on entry, theres 10 entry by page, and around 130 total page.
how can I handle an action on the same view while still retaining the paging in memory …
@using (Html.BeginForm())
{
<label>All Logs since :</label> <input id="startDate" name="startDate" class="datepicker" type="text" value="@Model.option.startDate.Value.ToString("dddd, dd MMMM yyyy")" />
<input type="submit" />
}
When this is submitted, I want the table to be filter base on the start Date. But if the user click on a page link, I need this research result to override the default setting in my view. heres the action in my controller :
[HttpGet]
public ActionResult Index(int? id)
{
MainViewModel model = new MainViewModel();
model.option = new LogOption();
model.option.numberOfResultPerPage = 10;
model.option.startDate = (method to set default date)
model.option.startPageIndex = id ?? 1;
*** call to service with the model.options as filter and set my table's column info and retreive the logs total in a custom class ( model.listing ) ***
model.totalPage = model.listing.TotalPages;
return View(model);
now when the user submit a new Date, I do the exact same thing, but with a small difference, which is to set the default date to something like that :
[HttpPost]
public ActionResult Index(LogOption mod)
{
model.option.startDate = mod.startDate;
}
the problem is that if after the startDate filter have been modified, if the user click to change the page from my table, the get action is called again, and I dunno how to handle the overriding of the original default setting. can i do that in a cleaner way without having to set the info in session ?
I guess I need to pass the model along with the get info, but I havent been able to do it .
[HttpPOST]
public ActionResult Index(MainViewModel mod, int? id)
{
}
but my MainViewModel is always null when I do this, so I dont know how to get both information aside from saving it in session, but I was told to avoid that and that it was possible to do it other way
I just realise I was trying to save my GET info into the POST action … which is kinda stupid logic