简体   繁体   中英

.net core 3.1 mvc razorpage edit method httppost 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 not fire action, i am using metronic theme integration and then not working post method.
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 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");}
}

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://docs.microsoft.com/en-us/aspnet/core/mvc/views/working-with-forms?view=aspnetcore-3.1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM