Last post Mar 12, 2018 09:30 AM by nideeshm
Feb 26, 2018 08:27 AM|bluMarmalade|LINK
Hi, i'm reading and trying out the new razor pages, but I see no particular advantages in using this feature. What are your thoughts and am I wrong on this:
1) Razor pages are not easier to make or easier for beginners as an intruduction to asp.net core. So in my mvc project adding a razor page section is not quicker than adding a normal view folder and a controller. In fact, usually the mvc style has less code
and files as the controller can be used for many views, whereas the razor page behind is for a specific view(razor page). Also, you usually have another layout view and viewimports file there that is not always wanted.
For beginners the razor pages are more confusing. The name itself is confusing because we already have the name "razor" for a view in mvc. Why not call it something more specific? Also the classic code behind style where also the viewmodel can be placed
can quickly become spaghetti land. Furthermore, i'm worried because it seems to me that Microsoft is really pushing razor pages as the standard way of creating an asp.net core app. Is this going to be the way to do it, while asp.net core web api is the only
other alternative (bercause single page apps would then be the client)?
2) performance. This would for me be the biggest reason to use razor pages. But do they give any performance benefit? I have read nothing about this and as far as I can test, it seems to have the same startup speed as normal mvc views?
3) Some things can't easily be used by razor pages, like view components. Partial views can be used but that is not as practical if you have more advanced features.
Are there any other benefits to razor pages? Please, I really want to know!! All who answers will be given green because my questions aren't specific and all answers are right on this.
Feb 26, 2018 10:14 AM|XIII|LINK
first time I saw them I thought we were going back to webforms but after more closely looking into them they can provide less clutter in your folder structure. Nowadays people tend to work with Features in MVC to try to keep things together for a specific
domain instead of having to look in the Controllers folder, the Views folder, the ... folder to combine things. With Pages you can combine these pages with their code in one Pages folder (or put subfolders in the Pages folder).
I suggest you take a look at https://msdn.microsoft.com/en-us/magazine/mt842512.aspx for more information and insights about them.
Btw, if you don't like/need them you can still make use of the traditional way of working with the default folders.
Feb 26, 2018 03:46 PM|bluMarmalade|LINK
Yes, I see that razor pages might lead to less clutter. But is this the only advantage? Why make a whole new thing just for that?
Feb 26, 2018 04:00 PM|bruce (sqlwork.com)|LINK
the idea of razor pages is too allow simple pages, that don't have enough server code to require a controller. also, for those coming from java, MVC matches spring, razor pages match jsp (although the old aspx syntax is a closer match).
if you are creating a brouchure site rather than an application site, you might find razor pages a better fit. the other good case for razor pages is if you are using a client framework like react, angular or vue and need to pass a little config information
(say url roots) in the startup page, that is you need a little more than a static html page.
Feb 28, 2018 01:08 PM|Tessalator|LINK
I think the way MS has presented Razor Pages is the problem. If you step back and look at them you will see that they can be very different from MVC. In my mind much better. The problem is MS treats them like MVC-Lite. This makes them seem more complicated
than they really are. Forget Controllers and Code-Behind - they are not MVC or WebForms. Think of them as self-contained HTML generators. You encapsulate everything you need in a single folder, and then you can reuse them as components. Remember Razor (pages)
are not HTML with C#. They are C# classes that will generate HTML. Treat them this way. Use your cshtml.cs as an HTML Provider, not a combined Model/Controller. Expose properties and methods that produce IHtmlContent. Your cshtml page is a palette where you
can compose a page from the IHtmlContent. Get your logic out of the cshtml.cs. Create a page handler classes for that. Also, don't think in CRUD terms. Think of them as classes with methods. Don't have your pages post models, have them "call methods" on the
pages. Forget trying to implement old (outdated) concepts in new technologies. Look at the possibilities from a new perspective.
Mar 12, 2018 09:30 AM|nideeshm|LINK
If you have an application which is nearly static like a brochure for your business, then you could go for Razor pages application. But if you want to build an ecommerce site or Enterprise level application then MVC is the answer.
Razor is also compiled using C# language. I think microsoft just wanted to increase its products / offering. Everything you have said about razor pages being confusing, higher learning curve, difficult to maintain etc is correct.