2011-10-17 73 views
0

我有一个路由问题,我一直在修补,但一直没有成功,试图让它工作。MVC3自定义路由隐藏行动

基本上,我有我的Global.asax文件默认路由和我有以下操作如下控制器:

控制器=人 操作=指数&搜索

当你参观的人网页你会得到一个搜索框,当你运行一个搜索,形式到达:

http://mysite/people/search?filter=a&searchType=IdentityCode&searchOption=StartsWith

我想要做的是,第降Ë搜索在URL中,所以它会是这个样子:

http://mysite/people?filter=a&searchtype=IdentityCode&searchOption=StartsWith

但仍运行搜索行动。

这是可能的吗?

回答

1

你可以通过索引和搜索相同的方法来做到这一点。

public ActionResult Index(string filter, string searchType, string searchOption) 
{ 

    IList<Person> people; 

    if (String.IsNullOrEmpty(filter)) { 
     people = peopleRepo.GetAll(); // Get all the people, or none - whatever you prefer on the index page 
    } 
    else 
    { 
     people = peopleRepo.Search(filter, searchType, searchOption); 
    } 

    Return View("index", people); 

} 

很明显,我已经拿到了许可证来解释你的代码,但我希望你明白。

+0

谢谢马特,那正是我需要的! – xqwzid

+0

不客气。 –