Answered by:
Razor: OnGet And OnPost

Question
-
User-1590999572 posted
Visual Studio Code 1.48 | .NET Core 3.1
Hi all
Two Methods can be used to process Forms: Get and Post
In the Razor Pages, in the Archive; for example Index.cshtml.cs the structure is implemented:
public class IndexModel : PageModel { public void OnGet() { } }
As can be seen, it works exclusively with Razor Pages without MVC Controllers
1 ° How to implement a Form in the Index.cshtml File to be processed by this same page, obviously using the OnGet Method?
2 ° Is it the same procedure for the OnPost Method (method = "post") or is there an additional variant?
Thank you very much
Wednesday, September 23, 2020 5:23 PM
Answers
-
User475983607 posted
Clearly, you did not bother going through the tutorial. Again, your asking very basic question covered in any beginning level Razor Pages tutorial. It makes no sense to copy the tutorial here.
The following link covers saving data in a database using Razor Pages.
https://docs.microsoft.com/en-us/aspnet/core/data/ef-rp/intro?view=aspnetcore-3.1&tabs=visual-studio
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, September 24, 2020 11:25 AM -
User-821857111 posted
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, September 24, 2020 1:55 PM
All replies
-
User475983607 posted
1 ° How to implement a Form in the Index.cshtml File to be processed by this same page, obviously using the OnGet Method?Forms are typically POSTed. It's possible to submit parameters in the URL (GET) but atypical.
2 ° Is it the same procedure for the OnPost Method (method = "post") or is there an additional variant?Your question is not clear. I recommend going through a beginning level tutorial to understand basic Razor Page programming pattern.
Wednesday, September 23, 2020 8:08 PM -
User-1590999572 posted
Mgebhard, Thanks for your reply, but ...
The Microsoft samples are very specific to a workbench, in addition to using their repositories on GitHub.
What I require is something simpler and more practical:
1º How to develop a simple Form to process Data that initially will not be entered into the Database but will be previously analyzed on the same page, for example Index, or on another, that is, retrieve and view the Data previously and if necessary apply certain processes to them before being entered into the Database?
2º How to establish and use the connection string to link with SQL Server 2014?
3rd Is the Scaffolding Tool mandatory? How to implement this utility to customize it according to specific requirements?
Please remember that the work is exclusively with Razor Pages and not with the MVC Architecture (that is, there are no Controllers)
Thank you very much already
Wednesday, September 23, 2020 11:56 PM -
User475983607 posted
Clearly, you did not bother going through the tutorial. Again, your asking very basic question covered in any beginning level Razor Pages tutorial. It makes no sense to copy the tutorial here.
The following link covers saving data in a database using Razor Pages.
https://docs.microsoft.com/en-us/aspnet/core/data/ef-rp/intro?view=aspnetcore-3.1&tabs=visual-studio
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, September 24, 2020 11:25 AM -
User-821857111 posted
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, September 24, 2020 1:55 PM