由於某種原因,我的應用程序未正確路由到我的控制器方法。我有這樣的routelink在我的網頁 -自定義路由未找到控制器操作
<%= Html.RouteLink("View", "Blog", new { id=(item.BlogId), slug=(item.Slug) }) %>
在的global.asax.cs我有以下途徑 -
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"MoreBlogs",
"Blog/Page/{page}",
new { controller = "Blog", action = "Index" }
);
routes.MapRoute(
"Blog",
"Blog/View/{id}/{slug}",
new { controller = "Blog", action = "View"}
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Blog", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
然後我有了一個方法的類BlogController -
public ActionResult View(int id, string slug)
{
... etc.
}
我在View方法的第一行放置了一個斷點,但它根本沒有被擊中。我使用路由調試器檢查了localhost/Blog/View/1/test格式,並匹配了我的自定義路由。我得到的是一個404運行這個,我不知道爲什麼路線不會發布到我的控制器中的視圖方法 - 任何想法?
你可以發佈調試器結果的屏幕截圖嗎? – 2010-06-02 19:29:00
我剛剛意識到兩個答案都基於假設。請用更多信息更新問題。謝謝。 – Ahmad 2010-06-03 06:43:37