level 9
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcGod.Models;
using Webdiyer.WebControls.Mvc;
namespace MvcGod.Controllers
{
public class ProductsController : Controller
{
//
// GET: /God/
private NORTHWNDEntities ne = new NORTHWNDEntities();
public ActionResult Index(int? pageIndex)
{
ViewBag.productCategory = new SelectList(ne.Categories.ToList(), "CategoryID", "CategoryName");这里说不能OPen,我都不知道那里有问题,软件上都没提示那里出现错误
PagedList<Products> pl = new PagedList<Products>(ne.Products.ToList(), pageIndex ?? 1, 5);
return View(pl);
}
public ActionResult Search(string pname,int? productCategory,int? pageIndex)
{
ViewBag.productCategory = new SelectList(ne.Categories.ToList(), "CategoryID", "CategoryName");
// pname = pname.Trim();
var plist = from p in ne.Products
//where p.ProductName.Contains(pname)
select p;
if (!String.IsNullOrEmpty(pname))
{
pname = pname.Trim();
plist =from p in ne.Products
where p.ProductName.Contains(pname)
select p ;
}
if (productCategory != null)
plist = from p in plist
where p.CategoryID == productCategory
select p;
PagedList<Products> pl = new PagedList<Products>(plist.ToList(),pageIndex ?? 1,5);
return View ("Index",pl);
}
}
}
2016年09月20日 08点09分

