How do I generate a webapi url from an MVC view?

后端 未结 1 736
天涯浪人
天涯浪人 2020-12-11 14:54

Based on How to create ASP.NET Web API Url?

Neither of these plus a few more combinations of them I\'ve tried are working

 
  • 相关标签:
    1条回答
    • 2020-12-11 15:38

      You could use either of the following to generate links to Web API:

      1. @Url.HttpRouteUrl("DefaultApi", new {controller = "corpuserrequest"})
      2. @Url.RouteUrl("DefaultApi", new { httproute = true, controller = "corpuserrequest"})

      Usually you would use option 1., but sometimes you might need to use 2. like in the following post (this post doesn't necessarily use RouteUrl, but the idea is that in places where you do not have a convenient extension like HttpRouteUrl, in this case Html.BeginForm, you can use httproute=true to indicate that you are indeed trying to generate a url to a Web API route)

      ASP.Net WebApi: Invalid URL generated in BeginForm

      0 讨论(0)
    提交回复
    热议问题