1

在一个简单的 Asp.Net MVC 网页上,我有一个下拉列表。当从列表中进行选择时,我想将选定的值作为路由值传递给操作。IEhttp:\\mysite\mypage\selectedvalue

我的下拉列表是

@Html.DropDownList("id", Model.AllLocations, "Select your Location");

我提交表单的javascript是

 $("#id").on("change", function () {
                $("form").submit();
            })

如何将此添加到我的路线?

这是一个移动网站,我需要在 url 中有值以适应预期的后退按钮使用。

** 编辑显示表格**

 @using (Html.BeginForm("details", "location",FormMethod.Post))
{
    @Html.AntiForgeryToken()
    @Html.DropDownList("id", Model.AllLocations, "Select your location");
}
4

1 回答 1

1

I actually had asked a similar question before. The situation is not exactly the same but I did get it to work with some javascript.

Similar question

   $("#id").on("change", function (e, p) {
            var val = $("#id option:selected").val();               
            var url = '@baseAddress' + '/location/details/' + val;

            window.location = url;

        })
于 2013-10-14T17:15:23.973 回答