在MVC列表视图上进行快速简单的过滤. [英] Quick and simple filtering on MVC List view.

查看:74
本文介绍了在MVC列表视图上进行快速简单的过滤.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用默认的(生成的)列表视图,并希望使用DropDown值对其添加过滤.我宁愿这样做而不求助于jQuery或JavaScript,而是使用普通的香草控制器动作来做到这一点.

我对此问题有几个组成部分:
1.是否需要为Index操作添加新路由以添加参数?
2.如何使按钮调用该新的参数化控制器动作?
3.如果我想使用一个小脚本在下拉列表值更改时调用该动作,该怎么办?

我正在使用自定义viewdata对象,其中包含我的主要模型数据以及下拉列表所需的列表.

I''m using a default (generated) List view, and would like to add filtering to it with DropDown values. I would prefer to do so without resorting to jQuery or JavaScript, and instead use plain vanilla controller actions to do this.

I have several components to this question:
1. Do I need to add a new route for the Index action to add parameters?
2. How do I cause a button to call that new parameterised controller action?
3. If I wanted to use a little script to call that action when dropdown values change, what should I do?

I am using a custom viewdata object, which contains my main model data as well as lists required for the dropdowns.

推荐答案

我真的不知道您的页面如何是内置的,但我建议使用以下内容:
将用于设置过滤器的DropDowns放在Ajax.Form中,并设置表单以更新结果数据应位于的面板(div).甚至可以包含自身的形式.
设置下拉菜单的onChange事件以提交表单.
这将使页面使用下拉列表值将请求发布到服务器,您可以在其中更新结果面板而无需刷新整个页面.
您只需现有控制器中的一个操作即可处理过滤器帖子,而无需新路线.
如果仅在按下按钮时才应用过滤器,而不使用DropDown的onChange事件,请在按钮的onClick事件中提交表单.
您不需要新参数,DropDowns的选定值将作为表单数据提交.
I really don''t know how your page is built but I would recomend the following:
Put the DropDowns that you use to set the filter in a Ajax.Form and set the form to update the panel (div) where the result data should be. That can even contain the form it self.
set the onChange event of the drop downs to submit the form.
That will make the page to post a request to the server with the drop downs values where you can update the result panel without refreshing the whole page.
You will not need a new route just an action in the existing controller to handle the filter posts.
If you want to apply the filter only when a button is pressed instead of using the onChange event of the DropDown submit the form in the onClick event of the button.
You don''t need new parameters the seected values of the DropDowns will be submited as form data.


这篇关于在MVC列表视图上进行快速简单的过滤.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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