I tried to create a simple HTML form like this using ASP.NET Core tag helpers:
<form asp-action="RemoveScheduledTenancyDeletion" method="put" asp-route-tenancyId="@Model.Tenancy.TenancyId">
<div class="form-group">
<input type="submit" value="Remove sheduled tenancy deletion" class="btn btn-default" />
</div>
</form>
In the TenancyController
there is a simple action:
[HttpPut]
public async Task<IActionResult> RemoveScheduledTenancyDeletion(Guid tenancyId)
{
//some logic here
return RedirectToAction(nameof(List));
}
I tried to check via developer tools if the form was generated properly:
and it seems ok to me, however, when I try to send a form Im getting an error:
It seems that somehow the whole request is transformed into the HttpGet
action.
Any ideas what can be wrong?
Out of the scope, I have a separate REST API where such kind of action is defined as HttpPut
and it works ok with Angular and other client-side apps which communicate with the API so I don't see any reason why I should not use HttpPut
as well in the ASP.NET Core MVC app. Am I missing something?
Cheers
HTML forms don't support PUT, DELETE, etc.: only GET and POST. If you need to send a PUT, you'll need to use AJAX to do so.