1
我在ASP MVC是新手,目前,我的演示項目結構是這樣的:ASP MVC路由配置 - 資源無法找到錯誤
Areas -- Comment -- Controller -- HomeController
-- ManageController
Controller -- HomeController
|-- CommentController
|____ PostMsg
|____ DeleteMsg
Views -- Home
| |--- Index.cshtml
|-- Comment
|--- PostMsg.cshtml
|--- DeleteMsg.cshtml
當我瀏覽的網址,如:
http://localhost/Comment/Manage/ --> return view successfully
http://localhost/Comment/PostMsg --> error "The resource cannot be found."
任何人有任何想法,爲什麼ASP MVC沒有解決我的控制器:-(
,這裏是我的global.asax.cs航線配置:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "Demo.Web.Controllers" }
);
這裏是我區登記航線配置:
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Comment_default",
"Comment/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { "Demo.Web.Areas.Comment.Controllers" }
);
}
問題:評論/ PostMsg URL被解析爲在留言區域的控制器
目標:評論/ PostMsg URL被解析爲CommentController的行動
任何幫助:-)
解決的問題,編輯區REGI理解共探路線配置(變通):
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Comment_default",
"Comment/PostMsg",
new { controller = "Comment", action = "PostMsg", id = UrlParameter.Optional },
new[] { "Demo.Web.Controllers" }
);
context.MapRoute(
"Comment_default",
"Comment/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { "Demo.Web.Areas.Comment.Controllers" }
);
}
Ø f cos我有PostMsg操作:-(在視圖\評論\文件夾中的PostMsg.cshtml :-( –
對不起,在Demo.Web.Areas.Comment.Controllers – vlukham
我不想推動區域內的PostMsg操作。 Comment.Controller.HomeController。我的目標是在CommentController中調用PostMsg操作:-) –