In my website with paging and search options i have to redirect the user and pass the search options. With this action I don't want to pass the search model with the URL (ex. http://localhost:1234/?Project.Models.TestModel=....).
My actionlink right now is as follows:
@Html.ActionLink(i.ToString(), "Index", new { idtrips = Model.idTrips, inituser = Model.initUser, date = Model.date.ToString("ddMMyyyy"), page = i})
When clicked this results in a following header: http://localhost:58763/?idtrips=0&inituser=0&date=05042016&page=5
My question is: Can you somehow add if clauses to the Html.ActionLink to only give values if they are needed. For example I only have a date set, then I want the Url to be: http://localhost:58763/?date=05042016&page=5. The other values have a default value in my controller so this url will work but i'm not able to generate it.
My controller:
public ActionResult Index(long idtrips = 0, long inituser = 0, string date = "", int page = 1)
{ ... }
What i'm looking for is something like this,:
@Html.ActionLink(i.ToString(), "Index", new { if(Model.idTrips > 0) { idtrips = Model.idTrips,} page = i})