ASP.NET MVC4 设置路由的命名空间 namespace

如果添加了多个区域(Area)就需要设置不同区域的路由的命名空间

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace MvcApplication1
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
                namespaces: new[] { "MvcApplication1.Controllers" }
            );
        }
    }
}

猜你喜欢

转载自blog.csdn.net/u012997311/article/details/80077840