Asp.net mvc 使用@Html.dropdownlist从dropdownlist获取所选值

Asp.net mvc 使用@Html.dropdownlist从dropdownlist获取所选值,asp.net-mvc,asp.net-mvc-4,Asp.net Mvc,Asp.net Mvc 4,下面是代码。所选值将发送到控制器 @Html.DropDownList("pagesize", new List<SelectListItem> { new SelectListItem() {Text = "10", Value="10"}, new SelectListItem() {Text = "20", Value="20"}, new SelectListItem() {Text = "30", Value="30"}, new Selec

下面是代码。所选值将发送到控制器

@Html.DropDownList("pagesize", new List<SelectListItem>
{
    new SelectListItem() {Text = "10", Value="10"},
    new SelectListItem() {Text = "20", Value="20"},
    new SelectListItem() {Text = "30", Value="30"},
    new SelectListItem() {Text = "40", Value="40"}
}, new { onChange = string.Format("location.href = '{0}'", @Url.Action("Logs", "Logging")) }) 

删除
onChange
属性并使用。函数需要将所选值作为路由参数添加到url

var url = '@Url.Action("Logs", "Logging")';
$('#pagesize').change(function() {
  location.href = url + '?pagesize=' + $(this).val();
}
旁注:您应该在控制器中生成SelectList,但在任何情况下都可以简化为

@Html.DropDownList("pagesize", new SelectList(new List<int>(){ 10, 20, 30, 40 }))
@Html.DropDownList(“页面大小”,新选择列表(新列表(){10,20,30,40}))

Yo代码不会将所选值传递给控制器。您需要修改url以添加所选值这是我想要的选择值我没有从给定的下拉列表中获取它,将所选值添加到url的过程是什么
@Html.DropDownList("pagesize", new SelectList(new List<int>(){ 10, 20, 30, 40 }))