ghazyy
ghazyy

Reputation: 749

Including All querystring parameters in Html.ActionLink

In 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>
    }

Regarding the option the user choose i generate a list and the Querystring in my address going to be like :

localhost/menu/list?groupName=controlpanel

My problem is when i use HtmlActionLink for example :

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

What i got in result is result is :

localhost/menu/List?foo=123

instead of :

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

Am i missing something ??

Upvotes: 4

Views: 6475

Answers (2)

hawkke
hawkke

Reputation: 4262

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

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

Upvotes: 1

felipeclopes
felipeclopes

Reputation: 4070

It is not a built in solution, even though it seems to address exactly what you are looking for:

ASP.NET MVC Build Url Based on Current Url

Upvotes: 5

Related Questions