我很確定我只是錯過了一些明顯的東西,但是這裏發生了什麼。ASP.NET MVC路由問題 - 視圖'營銷'或其主人沒有被發現或沒有視圖引擎支持搜索的位置
我加入到我的RouteConfig.cs文件的自定義路徑,如下所示:
routes.MapRoute(
name: "LibraryCategoryList",
url: "Library/List/{id}",
defaults: new { controller = "Library", action = "List", id = "Marketing" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "BFRDP.Controllers" }
);
我有一個名爲圖書館與動作列表控制,具體如下:
public ActionResult List(string id)
{
return View(id);
}
我的列表視圖在〜/ Views/Library/List.cshtml。
當我嘗試去http://localhost:49591/Library/List/Marketing,我得到的錯誤:
The view 'Marketing' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/Library/Marketing.aspx ~/Views/Library/Marketing.ascx ~/Views/Shared/Marketing.aspx ~/Views/Shared/Marketing.ascx ~/Views/Library/Marketing.cshtml ~/Views/Library/Marketing.vbhtml ~/Views/Shared/Marketing.cshtml ~/Views/Shared/Marketing.vbhtml
(是的,我確實有RouteConfig.RegisterRoutes(RouteTable.Routes);在我的Global.asax Application_Start方法中。 cs文件)。
我在做什麼錯了?
謝謝!
Laurie
沒有必要爲LibraryCategoryList路線。第二條路線對於「圖書館/列表/市場營銷」的請求也是一樣的。 –
您使用[View]方法的[this overload](https://msdn.microsoft.com/en-us/library/dd460352(v = vs.118).aspx) - 即指定視圖名稱。如果您想將值「Marketing」作爲模型傳遞給'List.cshtml'視圖,則使用'return View((object)id);' - 即[this overload](https://msdn.microsoft。 com/en-us/library/dd492930(v = vs.118).aspx) –
Stephen - 謝謝,那修好了! –