ASP.NET MVC过滤结果列表/网格 [英] ASP.NET MVC Filtering results in a list/grid

查看:119
本文介绍了ASP.NET MVC过滤结果列表/网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,我坚持这一点。我需要从基于同一视图一个DropDownList视图筛选结果。其基本思路是这样的:我有属于各个合作伙伴提供的名单,但提供者列表中包含了所有的供应商一起(针对所有的合作伙伴)。我需要能够通过合作伙伴来显示供应商的时候有人想看到的只是该合作伙伴(否则,默认的上市将所有提供)。我的看法是目前的默认(显示所有),但由于某种原因,林坐在这里盯着显示器(在最后2小时!)试图找出如何筛选这些结果。

For some reason I'm stuck on this. I need to filter results from a View based on a DropDownList in the same view. The basic idea is this: I have a list of providers that belong to various partners, but the provider list contains ALL the providers together (for all partners). I need to be able to display the providers by partner when someone wants to see just that partner (otherwise, the default listing will be ALL providers). My view currently is the "default" (showing all), but for some reason Im sitting here staring at the monitor (for the last 2 hours!) trying to figure out how to filter these results.

任何建议,从哪里开始/怎么办呢?!

Any suggestions where to start/how to do it?!

推荐答案

编辑:如果您想使用jQuery和AJAX(这将提供更好的用户体验,要做到这一点,因为只有细分列表会刷新),请参见本教程

If you want to do this with jQuery and AJAX (which will provide a better user experience because only the subdivisions list will refresh), see this tutorial.

如果我理解正确的话,你基本上想做的WebForms式回发。

If I understand correctly, you basically want to do a WebForms-style postback.

假设你有国家和国家细分(如州,省等)的控制。当国家的变化,你要适当的细分​​显示。

Let's say you have a control with countries and country subdivisions (e.g. states, provinces, etc). When the country changes, you want the appropriate subdivisions to display.

所以,这将是观点:

<% using (Html.BeginForm()) { %>
    <%=Html.DropDownList("Address.CountryId", new SelectList(Country.GetAll(), "Id", "Name"), new { onchange = "this.form.submit();" })%>
    <%=Html.DropDownList("Address.CountrySubdivisionId", new SelectList(CountrySubDivision.GetByCountryId(Model.CountryId), "Id", "Name"))%>
    <input type="submit" name="btnSubmit" value="Submit"/>
<%} %>

这是关键,越来越依赖列表过滤:

This is the key to getting the dependent list to filter:

new { onchange = "this.form.submit();" }

和控制器,你有这样的事情:

And in the controller, you'd have something like this:

    [AcceptVerbs(HttpVerbs.Post)]
    public ViewResult Index(string btnSubmit)
    {
        if (btnSubmit == null)
        {
            // return the view displayed upon GET
        }
        else
        {
            // process the submitted data
        }
    }

在上面的code,如果表单提交通过改变在下拉值触发,btnSubmit按钮将为空。因此,你要发布帖子的动作可以告诉用户是否并不意味着完成了她的变化。

In the above code, if the form submission was triggered by changing the value in a dropdown, btnSubmit will be null. Thus, the action you are POSTing to can tell whether or not the user meant to finalize her changes.

这篇关于ASP.NET MVC过滤结果列表/网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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