I'm trying to get a simple MVC page to PUT
to my Controller. GET
and POST
will work fine, but I am doing an Update, so a PUT
is more applicable, and it's calling the WebAPI backend with a PUT just fine.
I've created a new base project and replicated the issue too. If I POST a form it is caught by the controller. If I change the same controller endpoint to HttpPut
and change the form to Put
, it doesn't. Instead a GET
is called!
I'm aware of the WebDAV fix in web.config
, but this is Core 3.1, so there is no web.config
. Does anyone know how to affect that same WebDAV fix in 3.1? If that is in fact the issue.
I've replicated the issue with this minimal code:
HomeController.cs
public class HomeController : Controller
{
public IActionResult Index()
{
var model = new IndexViewModel();
return View(model);
}
[HttpPut] // Change this to HttpPost
public IActionResult Index(IndexViewModel model)
{
Debug.Print(model.Text);
return RedirectToAction("Index");
}
}
IndexViewModel.cs
public class IndexViewModel
{
public int Id { get; set; }
public string Text { get; set; }
}
Index.cshtml
@model IndexViewModel
<div class="text-center">
<form asp-action="Index" method="put"> @*Change this to method="post"*@
<input type="hidden" asp-for="Id" />
<input type="text" asp-for="Text" />
<button type="submit">Go</button>
</form>
</div>