Last post Feb 26, 2020 09:12 PM by Mikesdotnetting
Feb 23, 2020 08:34 PM|replicator2699|LINK
I'm new to web development and decided to pick ASP.NET Core for a project since I have prior knowledge of C#. I don't have any experience with JS, but I have a good grasp of OOP. I will be writing a basic reservation system for a tourism company, but we
will add other features in the future, so it is not going to stay as a small project. Considering this, should I go with MVC pattern or should I stick to razor pages and learn that instead?
Feb 24, 2020 07:51 PM|Mikesdotnetting|LINK
Razor Pages is the recommended way to build server-side websites these days. It's a lot easier to work with than MVC and is just as powerful. Microsoft recommend that controllers should only be used for Web APIs.
Here's a starting point: https://www.learnrazorpages.com
Feb 25, 2020 08:40 PM|replicator2699|LINK
Thank you for your answer! I've started experimenting with Razor Pages and the web site you mentioned has been very helpful. Now I have couple more questions:
How should the project structure be? I only have one project and I am writing all the code for business logic in cshtml.cs files for that specific page at the moment. This includes database operations. I have a Model folder for my models and a Data folder
that contains my Db Context, but other than that, everything is under the Pages folder, in their respective subfolders. I believe there are times I move away from single responsibility principle and sometimes it feels like the code won't be expandable and maintainable
even in the short term. I would be glad if you can give me some tips about code design and structuring using Razor Pages.
Also, related to above, I am kind of confused about where the Razor Pages stands in terms of back-end and front-end development. Should I create another project and write a Web API for the site and use Razor Pages only for UI? The good thing is I am moving
forward very quickly like this, but I also worry about problems I might encounter as the project gets bigger and more complicated.
Feb 26, 2020 07:06 AM|jiadongm|LINK
Razor Pages provides an abstraction over the top of MVC, which makes it better suited to some
You can take a look at the difference between Razor Pages and traditional MVC and have a better understand how do they work.
Feb 26, 2020 09:12 PM|Mikesdotnetting|LINK
You would organise a Razor Pages application in a similar way to an MVC application. The traditional Presentation - Business Logic - Data Access layer approach is just as valid for Razor Pages.
I usually create a "service" layer (Business Logic) that calls methods in a Data Access layer (repositories, Entity Framework or whatever) and call the service layer methods in the PageModel handler methods. In a large application, I might even create the
layers as separate projects.
API endpoints return data (as JSON by default), not HTML. They can be useful if parts of your page are driven by AJAX. There's an example here: https://www.learnrazorpages.com/web-api