Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my HTTP edit post method not working?

When I try to submit my form, my request is not reaching the Post-method 'Edit and is returning HTTP Error Code 415.

My Razor page does not fire an action, I am using metronic theme integration and then not working post method. The following is the server-side code:

[HttpPost]
[ValidateAntiForgeryToken]        
public async Task<IActionResult> Edit(int id, [FromForm] Firma firma)
{
    //code here[enter image description here][1]
}

And the following is the client side code:

@model satinalma.Models.Firma
@{
    ViewData["Title"] = "Edit";
}
<form asp-action="Edit">
    <div asp-validation-summary="ModelOnly" class="text-danger"></div>
    <input type="hidden" asp-for="Id" />
    <div class="form-group">
        <label asp-for="Baslik" class="control-label"></label>
        <input asp-for="Baslik" class="form-control" />
        <span asp-validation-for="Baslik" class="text-danger"></span>
    </div>
    <div class="form-group">
        <input type="submit" value="Save" class="btn btn-primary" />
    </div>
</form>

@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
like image 677
sak1065 Avatar asked Jul 09 '26 19:07

sak1065


1 Answers

You've got the asp-action tag helper for the method, but not one for the controller. Try adding that and see if it routes properly.

https://learn.microsoft.com/en-us/aspnet/core/mvc/views/working-with-forms?view=aspnetcore-3.1

like image 98
cjens19 Avatar answered Jul 11 '26 11:07

cjens19



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!