Show categor...">

Enabling all request parameters in Html.ActionLink

On my page I have

@using (Html.BeginForm("list", "menu", FormMethod.Get)) { <div> Show categories: @Html.DropDownList("groupName", (SelectList)ViewBag.groups) <input id="Submit1" type="submit" value="Show" /> </div> } 

As for the option that the user selects, I create a list, and the Querystring in my address will look like this:

 localhost/menu/list?groupName=controlpanel 

My problem is that I am using HtmlActionLink, for example:

 @Html.ActionLink("Title", "List", new { foo = item.foo}) 

As a result, I got the result:

 localhost/menu/List?foo=123 

instead:

  localhost/menu/List?foo=123&groupName=controlpanel 

Am I missing something ??

+4
source share
2 answers

This is not a built-in solution, although it seems to be addressing exactly what you are looking for:

ASP.NET MVC Build Url Based on Current URL

+5
source

To use ActionLink, you need to include all the parameters that you want to display in the query string. The easiest thing I think is to add the GroupName property to your model (or to the ViewBag, like your other sample). Then you can do this:

 @Html.ActionLink("Title", "List", new { foo = item.foo, groupName = Model.GroupName }) 
+1
source

Source: https://habr.com/ru/post/1442850/


All Articles