我想訂購一些基於價格的產品。我傳遞給我的動作的參數是什麼?我如何使用它從IQueryable<Product>
進行排序?asp.net mvc根據控制器中的參數訂購商品
例如,這是我目前有:
public ActionResult Index(int page =0, int cat = 0, int subCat =0)
{
var products = productService.GetAllProducts();
ProductListViewModel model = new ProductListViewModel();
if (cat > 0)
{
products = products.Where(p => p.SubCategory.CategoryId == cat);
}
if (subCat > 0)
{
products = products.Where(p => p.SubCategory.SubCategoryId == subCat);
}
products = products.OrderBy(p => p.CreatedDate);
model.PagedProducts = products.ToPagedList(page, 15);
return View(model);
}
如果你只是想按價格排序,在行動中不應該有任何需要通過的東西 - 你是否試圖篩選到潛艇?等產品的基礎上的一些參數? – ataddeini 2011-05-11 16:36:54
我在我的頁面上有兩個網址,一個表示按最高價格排序,另一個表示最低價格優先。 – 2011-05-11 16:43:02