Allan
asked on
can mvc5 coexists with razor
ASKER
Thanks Misha.
In asp.net core 2.0 if you pass the name of the razor page to the HTTP request the MVC Framework will look at the ‘Pages’ folder and find the matching ‘.cshtml’ file called “Greeting”. So, the MVC pattern can co-exists with a razor page.
However, we’re not sure, if it’s even possible, to wire, it so that the routing engine will see that it’s not a Controller, but a razor page. In MVC5 the method “Application_Start” of the file “Global.asax.cs” contains a call the routing definition: “RouteConfig.RegisterRoute s(RouteTab le.Routes) ;”.
The question is if you know and how if we can get the MVC pattern to co-exists with razor pages.
Does this make sense? Thanks!
In asp.net core 2.0 if you pass the name of the razor page to the HTTP request the MVC Framework will look at the ‘Pages’ folder and find the matching ‘.cshtml’ file called “Greeting”. So, the MVC pattern can co-exists with a razor page.
However, we’re not sure, if it’s even possible, to wire, it so that the routing engine will see that it’s not a Controller, but a razor page. In MVC5 the method “Application_Start” of the file “Global.asax.cs” contains a call the routing definition: “RouteConfig.RegisterRoute
The question is if you know and how if we can get the MVC pattern to co-exists with razor pages.
Does this make sense? Thanks!
If I correct understand you, you asked about ASP NET MVC 5, not about ASP NET CORE 2.0.
In ASP NET CORE you can route to page folder directly. Like in this small artcile:
https://exceptionnotfound.net/setting-a-custom-default-page-in-asp-net-core-razor-pages/
In ASP NET MVC you can route only to controller and method of controller, which return view.
You can create custom route like in this article:
https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/controllers-and-routing/creating-custom-routes-cs
But in this case you also need to specify controller and its method.
In ASP NET MVC you can use Razor syntax to get directly data from your model, create variables and use C# code in html (cshtml files)
You can read about using razor in MVC in this article:
https://docs.microsoft.com/en-us/aspnet/web-pages/overview/getting-started/introducing-razor-syntax-c
In ASP NET CORE you can route to page folder directly. Like in this small artcile:
https://exceptionnotfound.net/setting-a-custom-default-page-in-asp-net-core-razor-pages/
In ASP NET MVC you can route only to controller and method of controller, which return view.
You can create custom route like in this article:
https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/controllers-and-routing/creating-custom-routes-cs
But in this case you also need to specify controller and its method.
In ASP NET MVC you can use Razor syntax to get directly data from your model, create variables and use C# code in html (cshtml files)
You can read about using razor in MVC in this article:
https://docs.microsoft.com/en-us/aspnet/web-pages/overview/getting-started/introducing-razor-syntax-c
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Miguel. Wanted someone to confirm it can be done my creating a custom route. What we wanted to do for html stuffs is start going in the direction of using Razor and for use mvc for web api.
ASKER
Thank you for your time!
Your path, which you posted here means, that you call controller with name "Page" and method of this controller with name "test".
It doesn't exist.
If you want to work with this template, you should create controller class in the folder "Controllers", add method which return View() (type "ActionResult"),
and then right click on this method in MS Visual studion and select "create view".
In this case this view will be open, when you call this controller method,
Start to learn asp net mvc with this links:
https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/adding-a-controller
https://www.asp.net/mvc/overview