我正在尝试找出 ASP.Net MVC 5 中名为MVC.Grid的包之一。
我有如下模型:
public class MasterCustomer
{
public System.Guid Id { get; set; }
public string Code { get; set; }
public string Name { get; set; }
}
和这样的控制器:
public class MasterCustomersController : Controller
{
private ApplicationDbContext db = new ApplicationDbContext();
// GET: MasterCustomers
public ActionResult Index()
{
if (HttpContext.Request.Headers["X-Requested-With"] == "XMLHttpRequest")
return PartialView("_IndexGrid", db.MasterCustomers.ToList());
return View(db.MasterCustomers.ToList());
}
[HttpGet]
public PartialViewResult IndexGrid(String search)
{
return PartialView("_IndexGrid", db.MasterCustomers.Find(search));
}
}
我想把它分成两个问题:
这个控制器是如何工作的,当我进行排序或搜索时,即使没有用于操作的控制器句柄,它也会正确返回。例子 :
http://localhost/MasterCustomers?search=&sort=code&order=asc&_=1533109639307
http://localhost/MasterCustomers?search=&sort=code&order=asc&code-contains=tes&code-op=&code-contains=&_=1533109639308
即使我的控制器中没有
sort
andorder
orcontains
动作,这个动作也能很好地工作。遗憾的是,GlobalSearch的一项操作
search
无法正常工作。无论我输入什么,它都会返回所有数据。例子 :http://localhost/MasterCustomers?search=sdfasdfasdfasdfsadwrh2w3rwegaweg&_=1533109639344
如果我知道没有问题。1个作品也许我可以弄清楚第2个问题。