补充最好的方法"滤波器QUOT;选项MVC的行动,为ASP.NET MVC 4的新的Web API功能 [英] Best way to add "filter" options to MVC action, for new Web API feature of ASP.NET MVC 4
本文介绍了补充最好的方法"滤波器QUOT;选项MVC的行动,为ASP.NET MVC 4的新的Web API功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
新的Web API东西看起来不错。我会重新写我的网站的基础到API,但我已经得到关切地一对夫妇的情景。
The new Web API "stuff" looks great. I will be re-writing the foundation of my site into an API, but have a couple scenarios that I've got concern with.
这是个坏主意,有一个看起来像一个动作:
Is it a bad idea to have an action that looks something like:
的GetProducts(长MEMBERID,串类,INT minPrice,诠释maxPrice,...)
其中各变量是东西产物可以通过进行过滤。如果变量是空/空它不会使用它们来构建查询。
Where each variable is something the product can be filtered by. If the variable is null/empty it wouldn't use them to build the query.
或者是有达到同一个目标的另一种技术?
Or is there another technique for reaching the same goal?
推荐答案
您可以使用一个视图模型:
You could use a view model:
public class FilterViewModel
{
public long MemberId { get; set; }
public string Categories { get; set; }
public int MinPrice { get; set; }
public int MaxPrice { get; set; }
...
}
和则:
public IEnumerable<ProductViewModel> GetProducts(FilterViewModel filter)
{
...
}
这篇关于补充最好的方法&QUOT;滤波器QUOT;选项MVC的行动,为ASP.NET MVC 4的新的Web API功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文