What is a good way to persist querystring values in asp.net mvc?
If I have a url: /questions?page=2&sort=newest&items=50&showcomments=1&search=abcd>
Here's how I done it in Asp.Net Core, first assign the query string parameters to ViewBags in your controller:
[HttpGet("/[controller]/[action]/{categoryId?}/{contractTypeId?}/{locationId?}")]
public IActionResult Index(Guid categoryId, int contractTypeId, Guid locationId)
{
ViewBag.CategoryId = categoryId;
ViewBag.ContractTypeId = contractTypeId;
ViewBag.LocationId = locationId;
...
}
Then pass the values to your links like so:
@teachingCategory.Description (@teachingCategory.Rank)
@typeOfEmployment.Name
@item.Id
Note that every link keep its own actual value and pass the rest of the route values through what we passed to ViewBag.