Razor and Razor Views Pages

Can I mix Razor Pages with Razor Views in the same ASP.NET Core 2.0 application?

If I understand correctly, the advantage of using Razor Pages is that they do not need controller actions. In my application, I have several pages that simply return a React application. I feel that Razor Pages perfect for this, because all I need on the page is just a link to the bundle.js file.

Having said that, I have a few pages where I need a controller and submit the view model.

So, is it nice to have both pages and views, or should I stick to one and not mix them together?

+5
source share
1 answer

Read recently about the Razor pages in the docs and Rick Anderson (ASP.Core team member) said here that:

You can mix Razor controllers, views, and pages. RP can be tested per unit (using code). That's a good question. See https://github.com/aspnet/Mvc/issues/494#issuecomment-232534742 for motivation.

So you can mix. The only tiny problem in my opinion is that I read from the docs that:

Note. The layout is located in the Pages folder. Pages look for other views (layouts, templates, partial) hierarchically, starting from the same as the current page. This means that the layout in the pages can be used from any Razor page in the Pages folder.

This means that you cannot use the same layouts, templates, partial for both the Razor Page and View out of the box, without changing ASP conventions, or to write any custom solution to use the same layouts, templates partial for the page Razor, so for the View. Otherwise, their mixture looks great.

+5
source

Source: https://habr.com/ru/post/1270981/


All Articles