MVC5 Area not behaving properly

巧了我就是萌 提交于 2019-12-13 02:36:22

问题


This post is directly related to: MVC5 Area not working

That post fixed the index.cshtml issue, however it did not resolve each view for that controller. For example:

http://localhost:45970/Setup/Start gives the error that the resource cannot be found (basically a 404).

However http://localhost:45970/Setup/Setup/Start brings up the correct page.

So what needs to be reconfigured so that ALL views for that controller in the Setup Area will open properly?

Edit 1

Code from 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" }
            );
        }
    }
}

回答1:


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}

You can accomplish that without using any Area. You only need AdminController and SetupController using the default route.



来源:https://stackoverflow.com/questions/38988376/mvc5-area-not-behaving-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!