in razor pages, the view model and controller actions are merged into a page model. a razor page references a PageModel. so to add a form, add some model fields to hold data to your page model and create a razor page that references the IndexModel class,
and create a form that binds to the IndexModel fields just like you would in a Razor View.
note: the PageModel class file is optional, you can define it in the Razor Page.
For the page that has get and post methods, the <form method="post"> must be defined in the view.cshtml file for the page in order to post the form back to the post method on the page. I think that's what you're asking. .
Below is a link to Razor project out on Github you can examine. The folder in the project says Blazor but it's all Razor. You will see get/post on multiple Razor pages.
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?
3º 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)
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?
3º 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
MVC is not a architecture. MVC is a UI design pattern just like MVP and MVVM are UI design patterns that work with Windows desktop or ASP.NET Web UI(s) just like MVC works with either UI environment.
Also, Razor page solution uses the MVC pipeline, and as far as a connectionstring is concerned, .NET Core is .NET Core. It makes no difference if it's a Windows desktop or ASP.NET Web based solution using .NET Core, it all works the same in using the basic
functionality of the .NET Core framework such as basic usage on obtaining the connectionstring and many other basic functionalities of .NET Core. However, things are much simpler in ASP.NET Core where things are done for the developer as opposed to Windows
desktop Core where a developer has to dig in and figure things out, becuase there are no examples for Windows Core desktop solutions like there are for ASP.NET Core solutions.
One can use Mr. Wizard, which are the scaffolding tools and other such do it for the developer tools, or one figures out how to do things manually never needing to use Mr. Wizard ever. Of course, one doesn't need to use Mr. Wizard in Windows desktop or
ASP.NET Web solutions .NET Core or non Core if one chooses to do so, which is the only way to fly and the only way one really learns.
If you find the post has answered your issue, then please mark post as 'answered'.
Member
10 Points
13 Posts
Razor Pages: OnGet And OnPost Methods
Sep 23, 2020 05:21 PM|Skar.2007|LINK
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:
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
All-Star
58124 Points
15640 Posts
Re: Razor Pages: OnGet And OnPost Methods
Sep 23, 2020 08:27 PM|bruce (sqlwork.com)|LINK
try reading the docs for a basic example.
in razor pages, the view model and controller actions are merged into a page model. a razor page references a PageModel. so to add a form, add some model fields to hold data to your page model and create a razor page that references the IndexModel class, and create a form that binds to the IndexModel fields just like you would in a Razor View.
note: the PageModel class file is optional, you can define it in the Razor Page.
Contributor
4923 Points
4198 Posts
Re: Razor Pages: OnGet And OnPost Methods
Sep 23, 2020 08:48 PM|DA924|LINK
For the page that has get and post methods, the <form method="post"> must be defined in the view.cshtml file for the page in order to post the form back to the post method on the page. I think that's what you're asking. .
Below is a link to Razor project out on Github you can examine. The folder in the project says Blazor but it's all Razor. You will see get/post on multiple Razor pages.
https://github.com/darnold924/PubCompanyCore3.x
Member
10 Points
13 Posts
Re: Razor Pages: OnGet And OnPost Methods
Sep 23, 2020 11:52 PM|Skar.2007|LINK
Bruce, 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?
3º 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
Contributor
4923 Points
4198 Posts
Re: Razor Pages: OnGet And OnPost Methods
Sep 24, 2020 04:17 AM|DA924|LINK
MVC is not a architecture. MVC is a UI design pattern just like MVP and MVVM are UI design patterns that work with Windows desktop or ASP.NET Web UI(s) just like MVC works with either UI environment.
https://www.codeproject.com/Articles/383153/The-Model-View-Controller-MVC-Pattern-with-Csharp
https://www.codeproject.com/Articles/228214/Understanding-Basics-of-UI-Design-Pattern-MVC-MVP
Also, Razor page solution uses the MVC pipeline, and as far as a connectionstring is concerned, .NET Core is .NET Core. It makes no difference if it's a Windows desktop or ASP.NET Web based solution using .NET Core, it all works the same in using the basic functionality of the .NET Core framework such as basic usage on obtaining the connectionstring and many other basic functionalities of .NET Core. However, things are much simpler in ASP.NET Core where things are done for the developer as opposed to Windows desktop Core where a developer has to dig in and figure things out, becuase there are no examples for Windows Core desktop solutions like there are for ASP.NET Core solutions.
One can use Mr. Wizard, which are the scaffolding tools and other such do it for the developer tools, or one figures out how to do things manually never needing to use Mr. Wizard ever. Of course, one doesn't need to use Mr. Wizard in Windows desktop or ASP.NET Web solutions .NET Core or non Core if one chooses to do so, which is the only way to fly and the only way one really learns.