Html.BeginForm routing to Web Api

后端 未结 2 1776
悲&欢浪女
悲&欢浪女 2021-01-04 07:05

I am trying to get my page to post to my Web API controller, rather than my Area/Controller/Action. Here is what I have so far, I have tried using both Html.BeginForm and A

相关标签:
2条回答
  • 2021-01-04 07:17

    You would need to use BeginRouteForm as link generation to Web API routes always depends on the route name. Also make sure to supply the route value called httproute as below.

    @using (Html.BeginRouteForm("DefaultApi", new { controller="Entries", httproute="true" }))
    
    0 讨论(0)
  • 2021-01-04 07:33

    You can explicitly tell the links to post to the root by including the leading slash:

    @using (Ajax.BeginForm("", "", null, new AjaxOptions { HttpMethod = "POST", Url = "/api/Standing" }, new { id = "frmStandingAdd", name = "frmStandingAdd" }))
    
    @using (Html.BeginForm("", "/api/Standing", FormMethod.Post, new { id = "frmStandingAdd", name = "frmStandingAdd" }))
    
    0 讨论(0)
提交回复
热议问题