Mixing Web Api and ASP.Net MVC Pages in One Project

前端 未结 3 725
春和景丽
春和景丽 2020-11-28 10:20

How do I mix Web API and ASP.Net MVC pages in one project?

For instance, I have model User. I would like, within the same project, to have an ApiController that wou

3条回答
  •  眼角桃花
    2020-11-28 10:42

    I haven't changed the namespaces, the only thing that I had to do was register WebApi first, and then MVC route

    //First register WebApi router
    GlobalConfiguration.Configure(WebApiConfig.Register);
    //and register Default MVC Route after
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    

    and everything works great!

提交回复
热议问题