4

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 ??

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you.It seems it's the only way to handle it.By the way I'm using MvcPagedList which is smart enough to do the same when putting page links.
1

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

1 Comment

That's right but i want a general way in which works with multiple querystring parameters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.