MVC5区域无法正常运行 [英] MVC5 Area not behaving properly
问题描述
此帖子与以下内容直接相关: MVC5区域无效
This post is directly related to: MVC5 Area not working
该帖子解决了index.cshtml问题,但是并没有解决该控制器的每个视图.例如:
That post fixed the index.cshtml issue, however it did not resolve each view for that controller. For example:
http://localhost:45970/Setup/Start
会给出错误,指出找不到资源(基本上是404).
http://localhost:45970/Setup/Start
gives the error that the resource cannot be found (basically a 404).
但是 http://localhost:45970/Setup/Setup/Start
会显示正确的页面.
However http://localhost:45970/Setup/Setup/Start
brings up the correct page.
那么需要重新配置哪些内容,以便设置区域中该控制器的 ALL 视图能够正确打开?
So what needs to be reconfigured so that ALL views for that controller in the Setup Area will open properly?
编辑1
SetupAreaRegistration.cs中的代码
using System.Web.Mvc;
namespace BlocqueStore_Web.Areas.Setup
{
public class SetupAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Setup";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
name: "Setup_default",
url: "Setup/{controller}/{action}/{id}",
defaults: new { action = "Index", controller = "Setup", id = UrlParameter.Optional },
namespaces: new[] { "BlocqueStore_Web.Areas.Setup.Controllers" }
);
}
}
}
推荐答案
由于具有上述路由配置的名为 Setup
的区域,因此打开 http://localhost:45970/Setup/Start
将在 Setup
区域下执行 StartController
.因为没有在 Setup
区域下的 StartController
,但出现404错误,但是您可以打开 http://localhost:45970/Setup/Setup/Start
成功,因为您在 Setup
区域下具有 SetupController
和 Start
操作方法.
Since you have an Area named Setup
with the above route configuration, opening http://localhost:45970/Setup/Start
will execute StartController
under Setup
Area. You got 404 error because you don't have StartController
under Setup
Area, but you can open http://localhost:45970/Setup/Setup/Start
successfully because you have SetupController
and Start
action method under Setup
Area.
根据您的评论,您需要以下网址格式
Based on your comment, you want the following url patterns
http://{host}/Setup/{view}
http://{host}/Admin/{view}
您可以在不使用任何区域的情况下完成此操作.您只需要使用默认路由 AdminController
和 SetupController
.
You can accomplish that without using any Area. You only need AdminController
and SetupController
using the default route.
这篇关于MVC5区域无法正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!