0

I want to pass the value in my textbox 'location' to my route so that my route looks something like this

https://localhost:44300/Home/Results/San+Francisco?Day=01%2F28%F2015

right now my url looks like this

https://localhost:44300/Home/Results/5?Day=6

what do I change in the form to pass in San Francisco to the url as a parameter?

@{
    var routeValues = new RouteValueDictionary {{"Location", "5"}, {"Day", "6"}};
}

@using (Html.BeginForm("Results", "Home", routeValues, FormMethod.Post))
{
    <p>
        <input type="text" name="location" id="location" placeholder="Search For Classes" />
    </p>
    <p>
        <input class="btn btn-primary btn-lg" value='Submit' type="submit" />
    </p>
}

Here is my route

routes.MapRoute(
            name: "Results", // route name
            url: "Home/Results/{location}", // URL with parameters
            defaults: new { controller = "Home", action = "Results", location = UrlParameter.Optional }
        );
chuckd
  • 13,460
  • 29
  • 152
  • 331
  • HTML does not support that. – SLaks Jan 25 '15 at 20:44
  • The best you can do is add a hidden input for day - `` and then `@using (Html.BeginForm("Results", "Home", FormMethod.Get))` (no route parameters!) which will give you `/Home/Results/?location=San+Francisco&day=6`. Alternatively, make the route `url: "Home/Results/{day}` and use `@using (Html.BeginForm("Results", "Home", new { day = 6 }, FormMethod.Get))` which will give you `/Home/Results/6?location=San+Francisco` –  Jan 26 '15 at 04:51

0 Answers0