修改MVC中的路由值以传入文本框值

时间:2015-01-25 20:40:48

标签: asp.net-mvc asp.net-mvc-routing asp.net-routing

我想在我的文本框中传递值' location'到我的路线,以便我的路线看起来像这样

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

现在我的网址看起来像这样

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

我将在旧金山传递给url作为参数的表单中进行哪些更改?

@{
    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>
}

这是我的路线

routes.MapRoute(
            name: "Results", // route name
            url: "Home/Results/{location}", // URL with parameters
            defaults: new { controller = "Home", action = "Results", location = UrlParameter.Optional }
        );

0 个答案:

没有答案