I have got a view with search options to filter results:
@model GWeb.Models.FilterModel
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Search criteria</legend>
@(Html.Telerik().ComboBox()
.Name("UserName")
.BindTo(new SelectList(ViewBag.workerList as System.Collections.IEnumerable, "Id", "Desciption"))
.Value(Model.UserName))
@(Html.Telerik().DatePicker()
.Name("StartWork")
.Value(Model.StartWork))
@(Html.Telerik().DatePicker()
.Name("EndWork")
.Value(Model.EndWork))
<input type="submit" value="Filter" />
</fieldset>
}
@{Html.RenderPartial("EmployeeList", (IEnumerable<GWeb.Entities.Work>)ViewBag.employeeList);}
RenderPartial is a list of items that can be edit:
<td>
<a href="@Url.Action("Edit", "Admin", new { id = item.Id })">
<img src="/Content/edit.png" alt="Edit" title="Edit" width="22" height="22" />
</a>
Edit view is standard scaffold generated view.
FilterModel contains:
public class FilterModel
{
public string UserName { get; set; }
public DateTime? StartWork { get; set; }
public DateTime? EndWork { get; set; }
//...
}
The problem: When I edit one of the items and go back to main view the search ciriteria are gone. How can I remember values that were set to FilterModel? So that after editing or viewing item from list I could get back to the same filter options that I have set before?
Any help much appreciated!
This is a common scenario. I usually have search forms submit using GET rather than POST (default) and store the Request.UrlReferrer in HttpSession. Then use this session value for cancel and redirect actions.
here is an example: