How to create ASP.NET Web API Url?

前端 未结 4 826
無奈伤痛
無奈伤痛 2020-11-29 16:59

In ASP.NET MVC, we have @Url.Action for actions. Is there something similar like @Url.Api which would route to /api/controller?

4条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 17:50

    It works with the simpler form of Url.Action thus you don't have to reference any Routing names:

    Url.Action("ActionName", "ControllerName", new { httproute = "DefaultApi" })
    

    You might want to add an area = "" if the URL is needed within an Area. (Api controllers are outside of Areas by default.) I'm using MVC 4.

提交回复
热议问题