开发者

Using ASP.NET MVC2, How to make filters work with hackable urls?

Think about New Egg's e-commerce drill down model to start, where keyword links on the nav bar further limit the currently displayed product list with each selection.

I setup a house finder with Routes like this:

http://{website.com}/{Housetype}/{PriceLow}-{PriceHigh}
http://mysite.com/Residential/180000-230000
http://mysite.com/Commercial/300000-500000

But now I want to add links on the side navigation that further limit content:

1 Bedroom
2 Bedroom
4 Bedroom

1-4 Acres
4-10 Acres
10+ Acres

How would I pass and maintain selections between clicks using MVC? I think my opti开发者_JAVA技巧ons are:

  1. Keep adding named parameters in the query string like /{acres}:{low}-{high}, but this will require that all parameters exist, I wouldn't be able to pick more than one criteria, or I hit the max querystring length.
  2. Once I know the {housetype} and {price range} then flip to a totally different strategy, maybe passing an object (like a DTO) that will .AddCriteria( "Acres", ".gt.", "1"); .AddCriteria("Acres", ".lt.", "4"), etc.... This sounds very complicated
  3. Something else?

Again, looking for starter answers, the most common way (almost design pattern way) to send filter and sort criteria from a client to ASP.NET MVC. Links are helpful too.


I built a URL expression parser a few weeks ago that will filter an IQueriable based on expressions from a URL. Here's a blog post for the explanation. Basically you can build your own expressions and plug them into the parser... or you could do it the standard IQueriable way with something like /price-greaterthan-3/price-lessthan-4000/acres-lessthan-10/

Here's a link to the code

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜