我試圖創建一個通用的路線蛞蝓的工作,但我C#泛型的mvc路線總是得到一個錯誤使用彈頭
的想法是,而不是www.site.com/controller/action我在網址友好www.site.com/{slug}
eg www.site.com/Home/Open將代替www.site.com/open-your-company
錯誤
服務器 '/' 應用程序錯誤的資源不能發現
在我的Global.asax我
public static void RegisterRoutes(RouteCollection routes)
{
//routes.Clear();
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("DefaultSlug", "{slug}", new { controller = "Home", action = "Open", slug = "" });
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new
{
area = "",
controller = "Home",
action = "Index",
id = UrlParameter.Optional,
slug = ""
}
);
}
在我的一個cshtml
我有以下鏈接(即使它被評論,仍然有相同的錯誤)。
@Html.ActionLink("Open your company", "DefaultSlug", new { controller = "Home", action = "Open", slug = "open-your-company" })
編輯:HomeController的
public ActionResult Open() {
return View(new HomeModel());
}
證明'DefaultSlug'路線圖的行動。 – Nkosi
這個動作是在家裏打開'public ActionResult Open() { return View(new HomeModel()); }' –
但是我想你有一點,我看到INSIDE的HomeModel中有一些參數是按位置訪問的。將現在測試它 –