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

前端 未结 3 729
春和景丽
春和景丽 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 11:06

    You can put them in separate namespaces, e.g MyApp.Controllers.UsersController and MyApp.Controllers.WebAPI.UsersController.

    This would let you expose similar URI routes in MVC and WebAPI, eg:

    /users/1      << MVC view
    /api/users/1  << Web API
    

提交回复
热议问题