2014-10-31 102 views
0

我在我的項目中使用MVC5路由屬性。MVC5屬性路由不起作用

我在主頁上有搜索控件。當用戶點擊搜索按鈕時,控制值將被傳遞給搜索控制器操作。

使用MVC5路由屬性URL之前http://localhost:5344/Search/View1?City=XYZ&Cat=ABC

首頁控制器代碼:

public ActionResult IndexFront(string City, string Search, string hidCategory, string btnSubmit) 
    { 


     return RedirectToAction("View1", "Search", new { CityS = City, SearchS = Search, Cat = hidCategory });   


    } 

搜索控制器代碼:

[Route("Search/{CatS}/{CityS}/{SearchS?}", Name="SearchWithCityCat")] 
    public ActionResult View1(string CityS, string SearchS, string CatS) 
    { 

     var searchModel = new SearchModel(); 

     return View(searchModel); 

    } 

與路由屬性裝潢視圖1,然後點擊搜索按鈕,它之後顯示相同的URL並給出錯誤「找不到頁面」。

我沒有找到解決這個問題的方法。

我做得對嗎?

請幫忙。提前致謝。

+0

嘗試'返回RedirectToAction(「SearchWithCityCat」,「搜索」,' – artm 2014-10-31 07:51:39

回答

0

謝謝大家。

找到答案。我從家庭控制器傳遞錯誤的參數名稱。