0

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>
Red
  • 2,244
  • 2
  • 13
  • 34
  • This stack article is for .net core 2 but maybe help? https://stackoverflow.com/questions/48188895/asp-net-core-with-iis-http-verb-not-allowed – Damian70 Jun 22 '20 at 18:02
  • Thanks, but WebDAV isn't a think in core 3, and I now think it's only relevant to WebApi, which works fine. The question https://stackoverflow.com/questions/8054165/using-put-method-in-html-form that this has been marked a duplicate of nails it. In fact, I should make this an answer – Red Jun 23 '20 at 11:26

0 Answers0