MVC 单独做Controller的映射

创建一个空的解决方案
第一步:首先创建一个类库作为Controller  例如:App
第二步:创建一个MVC的空项目  注意命名  例如:App.Web
第三步:在web项目中添加域名为View
第四步:在Controller类库中添加一个类名为 AppAreaRegistration


using System.Web.Mvc;


namespace App
{
    public class AppAreaRegistration : AreaRegistration
    {
        public override string AreaName
        {
            get
            {
                return "App";
            }
        }


        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "App_default",
                "{controller}/{action}",
                new { action = "Index", id = UrlParameter.Optional }
            );
        }
    }
}


你可能感兴趣的:(MVC)