找不到mvc 3默认路由

时间:2012-04-01 22:49:43

标签: asp.net-mvc-3 routes

管理员部分的默认路由存在问题。 我从默认更改文件夹结构,现在我有结构如何在图片

for admin

for admin

模块的

for modules

我创建了两个ViewEngine AdminViewEngine和CoreViewEngine

AdminViewEngine

public class AdminViewEngine : RazorViewEngine
{
    public AdminViewEngine()
    {
        AreaMasterLocationFormats = new[] { "~/Admin/Views/Shared/admin.cshtml" };

        AreaPartialViewLocationFormats = new[] { "~/Admin/Views/Shared/Partials/{0}.cshtml", "~/Admin/Views/{1}/Partials/{0}.cshtml", "~/Admin/Menu/{0}.cshtml" };

        AreaViewLocationFormats = new[] { "~/Admin/Views/{1}/{0}.cshtml", "~/Admin/Menu/{0}.cshtml" };

        PartialViewLocationFormats = AreaPartialViewLocationFormats;
        ViewLocationFormats = AreaViewLocationFormats;
        MasterLocationFormats = AreaMasterLocationFormats;
    }

    protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath)
    {
        return new RazorView(controllerContext, partialPath, null, false, FileExtensions);
    }

    protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
    {
        if (string.IsNullOrEmpty(masterPath))
        {
            masterPath = AreaMasterLocationFormats[0];
        }

        var view = new RazorView(controllerContext, viewPath, masterPath, true, FileExtensions);
        return view;
    }
}

CoreViewEngine

public class CoreViewEngine : RazorViewEngine
{
    internal static readonly string Theme = SiteSettings.Instance.Theme;

    public CoreViewEngine()
    {
        string masterCatalog = string.Format("~/Themes/{0}/Views", Theme);
        string masterPath = string.Format("{0}/master.cshtml", masterCatalog);
        string partialThemesFolder = string.Format("~/Themes/{0}/Partials", Theme);

        MasterLocationFormats = new[] { masterPath };

        ViewLocationFormats = new[] { "~/Modules/Views/{1}/{0}.cshtml" };

        PartialViewLocationFormats = new[]
            {
                "~/Blocks/{0}.cshtml", partialThemesFolder + "/{0}.cshtml", "~/Modules/Views/{1}/Partials/{0}.cshtml",
                "~/Modules/Views/{1}/{0}.cshtml"
            };
    }

    protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath)
    {
        return new RazorView(controllerContext, partialPath, null, false, FileExtensions, ViewPageActivator);
    }

    protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
    {
        if (string.IsNullOrEmpty(masterPath))
        {
            string masterCatalog = string.Format("~/Themes/{0}/Views", Theme);
            masterPath = string.Format("{0}/master.cshtml", masterCatalog);
        }

        var view = new RazorView(controllerContext, viewPath, masterPath, true, FileExtensions, ViewPageActivator);
        return view;
    }
}

我有注册核心和管理员课程

public class ModulSetup : BaseModule
{
    public override void Setup()
    {
        this.SetupViewEngine();
        this.SetupControllers();
    }

    public override void SetupRoutes(RouteCollection routes)
    {
        routes.MapRoute("AdminRoot", "Admin", new { controller = "Site", action = "Index" });

        routes.MapRoute(
            "Admin",
            "Admin/{controller}/{action}/{id}",
            new { controller = "Site", action = "SiteSetting", id = UrlParameter.Optional });

        routes.MapRoute(
            "Default",
            string.Empty,
            new { controller = "News", action = "LastNews" });
    }

    protected void SetupViewEngine()
    {
        ViewEngines.Engines.Add(new CoreViewEngine());

        ViewEngines.Engines.Add(new AdminViewEngine());
    }

    protected override void SetupControllers()
    {
        ControllerBuilder.Current.DefaultNamespaces.Add("SGN.Core.Admin.Controllers");
    }
}

管理工作。但如果我尝试转到默认管理页面_http:// sitename / Admin /我得到404 我为注册路线尝试不同的变种。但没有帮助。我不知道我该做什么

0 个答案:

没有答案