Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are you still supposed to use controllers when using Razor Pages?

I'm confused on wheter you should still use controllers in your Core 2.0 project if you are using razorpages, since they removed the pre-made controllers folder from Core 1.0. Asking as im using Razorpages, Entity framework and sql.

like image 299
Mathias Andersson Avatar asked Mar 14 '18 10:03

Mathias Andersson


1 Answers

It is up to you. There are people who still use controllers in ASP.NET Core 2 because they do not like the idea of Razor Pages. You can have both of them in the same project. I personally like Razor pages but I still use Controllers when I have to make an ajax call in order to get data from server to update the contents of the page. For ajax calls I also use the razor page by defining handlers to get the data.

Controllers also can be used in a Razor Page project in order to create web services so that other application to be able to retrieve information from the Razor Page application.

like image 171
pitaridis Avatar answered Nov 15 '22 08:11

pitaridis