Add query string in HtmlHelper in ASP.NET MVC

I have a view with two HtmlHelpers that produce links, something like this

<li><%:Html.ActionLink("Link A", "Index", "HomeController")%></li>
<li><%:Html.ActionLink("Link B", "Index", "HomeController"})%></li>

Now I want to add a request to link B when it points to the following URL http: // localhost: 55556 / HomeController /? Sort = LinkB

I want both links pointing to the same controller so that I can determine if the String request is present and then point to the corresponding link to another view, something like ...

[AcceptVerbs(HttpVerbs.Get)]
        public ActionResult Index()
        {
            var linkChoice = Request.QueryString["Sort"];

            if (linkChoice == "LinkB")
            {
                return View("ViewB");
            }
            else
            {
               return View("ViewA");
            }
        }

Thanks for the help.

+3
source share
2 answers

Is there a reason you cannot use:

<li><%:Html.ActionLink("Link A", "Index", "HomeController", new { Sort = "LinkA" }, null)%></li>
<li><%:Html.ActionLink("Link B", "Index", "HomeController", new { Sort = "LinkB" }, null)%></li>
+2
source

. SO : QueryString.

<%= Html.ActionLink("Name", "Index", "Controller", new { Sort = "LinkB" }) %>
+1

All Articles