如何在MVC中创建Filter [英] How to create Filter in MVC

查看:80
本文介绍了如何在MVC中创建Filter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



我有品牌明智的产品清单

[已删除垃圾邮件链接]



此品牌有不同的类别和物品包装,价格等

如何为此创建和绑定过滤器



喜欢[已删除垃圾邮件链接]



我点击视频播放器,选择视频播放器显示所有品牌和类型和颜色


目前我有一个ProductView模型,其中包含产品和产品详细信息



请指导我如何操作。



在此先感谢:)

Dear Friends,

I have list of products with Brand wise
[Spam link removed]

This Brand has the different category and Pack of Items, price and etc
How to create and bind filter for this

Like [Spam link removed]

I have click the video-players, selection on video-players showing all Brands and Type and color

Currently i have one ProductView Model which contain the Product and product details

Please guide me How to do this .

Thanks in Advance :)

推荐答案

公共类FeaturedProduct:ActionFilterAttribute

{

私人DBEntities _entities =新DBEntities();

公共覆盖void OnResultExecuting(ResultExecutingContext context)

{

var viewData = context.Controller.ViewData;

viewData [featured] = GetRandomProducts();

}



private iList,product> GetRandomProducts()

{

var rnd = new Random();

var allproducts = _entities.Products.ToList();

var featuredProducts = new List,product>();

for(int i = 0; i< 5; i ++)

{

var product = allproducts [rnd.Next(allProducts.Count)];

allProducts.Remote(product);

featuredProducts.Add(product);

}

返回FeaturedProducts;

}

}
Public class FeaturedProduct :ActionFilterAttribute
{
Private DBEntities _entities = new DBEntities();
public override void OnResultExecuting(ResultExecutingContext context)
{
var viewData = context.Controller.ViewData;
viewData["featured"] = GetRandomProducts();
}

private iList,product> GetRandomProducts()
{
var rnd = new Random();
var allproducts = _entities.Products.ToList();
var featuredProducts = new List,product>();
for (int i = 0; i < 5; i++)
{
var product = allproducts[rnd.Next(allProducts.Count)];
allProducts.Remote(product);
featuredProducts.Add(product);
}
return featuredProducts;
}
}


好,我不能为你编写这么多代码,这是你应该自己做的事情。

但是这里的东西是:



< b> 1。首先,您需要考虑 PartialView



2。 列出所有产品并根据所选类别过滤它们。您可以充分利用 Isotop [ ^ ]插件。



3。明智地获取类别最小和最小最高价格并使用范围滑块 [ ^ ]给出该特定类别的价格范围。现在在更改滑块时,您可以使用PartialView过滤该范围内的产品。



4。您可以使用复选框了解颜色。



希望你明白了。 :)



-KR
Well, I cannot do this much coding for you, which is something you should do on your own.
But here's the things:

1. The first thing, you need to consider the PartialView for this.

2. List out all the products and filter them according to the Category selected. You can make excellent use of Isotop[^] plugin.

3. Get the category wise minimum & maximum price and using Range Slider[^] give a range of price of that particular category. Now on changing the slider, you can filter the products within that range show them using PartialView.

4. And you can use the Checkboxes for the colors.

Hope you got the idea. :)

-KR


这篇关于如何在MVC中创建Filter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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