I have the following:
@Html.ActionLink("Customer Number", "Search", new { Search = ViewBag.Search, q = ViewBag.q, sortOrder = ViewBag.CustomerNoSortParm, })
With both viewbag properties coming from the URL:
http://localhost:51488/Home/Search?Search=Postcode&q=test&sortOrder=CustomerNo
However the URL produced is:
http://localhost:51488/Home/Search?sortOrder=CustomerNo
with it not picking up either of the ViewBag values.
ViewBag doesn't come from the URL. It comes from the controller action. If you want to fetch query string parameters or parameters that were part of a POST request you could use the Request
:
@Html.ActionLink(
"Customer Number",
"Search",
new {
Search = Request["Search"],
q = Request["q"],
sortOrder = Request["CustomerNoSortParm"]
}
)