2011-10-17 122 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

不客氣。 –