Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get url parameter value of current route in view in ASP .NET MVC

For example I am on page http://localhost:1338/category/category1?view=list&min-price=0&max-price=100

And in my view I want to render some form

@using(Html.BeginForm("Action", "Controller", new RouteValueDictionary { { /*this is poblem place*/ } }, FormMethod.Get))
{
    <!--Render some controls-->
    <input type="submit" value="OK" />
}

What I want is to get view parameter value from current page link to use it for constructing form get request. I tried @using(Html.BeginForm("Action", "Controller", new RouteValueDictionary { { "view", ViewContext.RouteData.Values["view"] } }, FormMethod.Get)) but it doesn't help.

like image 994
Dmytro Avatar asked Sep 04 '12 15:09

Dmytro


2 Answers

I've found the solution in this thread

@(ViewContext.RouteData.Values["view"])
like image 171
Daniel Avatar answered Oct 18 '22 21:10

Daniel


You should still have access to the Request object from within the view:

@using(Html.BeginForm(
    "Action", 
    "Controller", 
    new RouteValueDictionary { 
        { "view", Request.QueryString["view"] } }, FormMethod.Get))
like image 28
Joel Etherton Avatar answered Oct 18 '22 21:10

Joel Etherton