ASP.NET MVC 3的DropDownList的SelectedIndexChanged [英] ASP.NET MVC 3 DropDownList selectedindexchanged

查看:105
本文介绍了ASP.NET MVC 3的DropDownList的SelectedIndexChanged的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一块功能,可以让用户根据自己的状态codeS来筛选记录。在菜单中,我有一个自定义过滤器部分:

I have a piece of functionality that allows users to filter records based on their own status codes. In the menu, I have a custom filters section:

<h3>Custom Filters</h3>
 <br />
   <ul id="ui-ajax-tabs">
      @{ Html.RenderAction("GetGroups", "Manage");}
    </ul>

和我的部分观点是这样的:

And my partial view looks like this:

@model IEnumerable<AllEngage.Model.Group>

@using AllEngage.Web.Helpers

@foreach (var group in Model)
{
    <li>
        <label for="@group.GroupName">@group.GroupName</label>
        @Html.DropDownList("GroupItems", group.GroupItems.ToSelectListItems())
    </li>
}

当从DropDownList中选择一个项目,我想一个操作方法在我的控制器火:

When an item is selected from a dropdownlist, I want an action method to fire in my controller:

[HttpGet]
public ActionResult Index(int page = 1, int groupFilterId = -1)

什么是去的最佳途径?用火JSON或执行后回来不知何故?

What would be the best way to go? Fire using json or perform a post back somehow?

推荐答案

您需要传递参数,你的行动。做到这一点的方式fastes - 通过查询字符串传递具有相同的名称作为行动参数:

You need to pass you param to action. The fastes way to do this - pass via query string with the same name as param in action:

http://mysite/GetGroups?groupFilterId=2

要刷新它,你需要用参数发送Ajax请求加入WTO要求将下拉控制被解雇的onchange 。指定过滤器控制一些ID:

To refresh it you need to send ajax request with param whitch will be fired onchange of the dropdown control. Specify some ID for your filter control:

@Html.DropDownList("GroupItems", group.GroupItems.ToSelectListItems(), new {@id="ddlFilter"})

,然后使用jQuery让你的数据的GET请求:

and then using jQuery make a GET request of your data:

$('#ddlFilter').change(function() {
  var queryLink = '@Url.Action("GetGroups")';
  if ($(this).val() != '') {
      queryLink += '?groupFilterId=2';
  }

  $.get(queryLink, function(data) {
      $('#ui-ajax-tabs').html(data);
  });
});   

这篇关于ASP.NET MVC 3的DropDownList的SelectedIndexChanged的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆