ASP.NET MVC routing and areas

后端 未结 2 1518
遥遥无期
遥遥无期 2020-12-30 06:38

I am messing around with ASP.NET MVC 2 Preview 2 and am trying to figure out how routing works with areas and such. In a single project implementation of areas, I want an a

相关标签:
2条回答
  • 2020-12-30 06:41

    Register areas in single project

    You have to add routes.cs file to the admin area folder.

        using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    
    namespace MvcAreasSingleProject.Areas.Admin
    {
        public class Routes : AreaRegistration
        {
            public override string AreaName
            {
                get { return "admin"; }
            }
    
            public override void RegisterArea(AreaRegistrationContext context)
            {
                context.MapRoute(
                    "admin_default",
                    "admin/{controller}/{action}/{id}",
                    new { controller = "Admin", action = "Edit", id = "" }
                );
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-30 06:51

    http://haacked.com/archive/2009/07/31/single-project-areas.aspx

    routes.MapAreaRoute("Forums", 
            "admin_area", 
            "admin/{controller}/{action}/{id}", 
            new { controller = "apples", action = "search", id = "" }, 
            new string[] { "Project.Areas.Admin.Controllers" });
    
    0 讨论(0)
提交回复
热议问题