I have a Form that should pass data through POST request, but GET request is being used without passing the data and do model binding of asp core, so buz of that the method Registrationp is never reach if the attribute [HttpPost] is in place ;( . I tried
many ways to get over this problem but none if them worked, even though the other forms post the data and bind the model successfully
Your sample code indicates you do not understand model binding. The HTML form should have FileId, FileName, OwnerId, and FileRep inputs. The only input in the HTML form is "img" which is not one of the Bind fields.
I also recommend going through the Getting Started tutorials on this site which also covers model binding and several other fundamental MVC programming patterns.
None
0 Points
2 Posts
the form Http POST doesn't work, only Get work in asp core mvc
Mar 28, 2021 10:06 AM|amnaw|LINK
I have a Form that should pass data through POST request, but GET request is being used without passing the data and do model binding of asp core, so buz of that the method Registrationp is never reach if the attribute [HttpPost] is in place ;( . I tried many ways to get over this problem but none if them worked, even though the other forms post the data and bind the model successfully
HTML:
Controller POST method:
None
0 Points
2 Posts
Re: the form Http POST doesn't work, only Get work in asp core mvc
Mar 28, 2021 10:45 AM|amnaw|LINK
Solved
All-Star
53711 Points
24031 Posts
Re: the form Http POST doesn't work, only Get work in asp core mvc
Mar 28, 2021 10:59 AM|mgebhard|LINK
Your sample code indicates you do not understand model binding. The HTML form should have FileId, FileName, OwnerId, and FileRep inputs. The only input in the HTML form is "img" which is not one of the Bind fields.
Learn model binding fundamentals.
https://docs.microsoft.com/en-us/aspnet/core/mvc/models/model-binding?view=aspnetcore-5.0
I also recommend going through the Getting Started tutorials on this site which also covers model binding and several other fundamental MVC programming patterns.
https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/start-mvc?view=aspnetcore-5.0&tabs=visual-studio
https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/?view=aspnetcore-5.0