mvc在Areas添加其他项目

 

1、Web.config从Views下拷贝一份;

2、添加ApiAreaRegistration.cs文件;

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

namespace WebApplication.Areas.api
{
    public class ApiAreaRegistration:AreaRegistration
    {
        public override string AreaName
        {
            get { return "api"; }
        }
        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "api_default",
                "api/{controller}/{action}/{id}",
                new { controller = "Home", action = "Index", id = UrlParameter.Optional }
                );
        }
    }
}

 3、在Global.ascx中注册

WebApiConfig.Register(GlobalConfiguration.Configuration);//注册webapi路由,最后放在前面

posted @ 2016-06-16 17:56  wjl910  阅读(128)  评论(0)    收藏  举报