The right time to use razor pages vs mvc - asp.net-mvc

I want to build an ecommerce website similar to amazon but the major difference is that users can register as companies and also register their own products within the website. I understand that mvc and razor web pages can be used side by side; I started a web application with razor web pages and it was stupidly easy to get up and running but now that I'm slightly further down the road (want to save users with different levels of permissions.) I beleive I may have to Transition my project
I've been reading some of the novel that is the microsoft documentation in addition to 3 other stack overflow links while researching.
Why is Razor Pages the recommended approach to create a Web UI in Asp.net Core 2.0?
ASP.NET Core 2.0 Razor pages vs Full MVC Core
What is difference between View and Page in Asp.net core 2?
I was just hoping to get some good input on when is the right time to use a razor page. because as I read more stuff it seems like I need to go undo some stuff and transition to mvc.

Related

asp.net webapi vs asp.net mvc restlike actions

I've been taking a look at the asp.net webapi stuff and I'm curious to know what the tipping point is for using it over using a normal mvc controller that supports rest like urls.
I've done a bit of a search and can't find any articles that specifically talk about when is the most appropriate time to use each.
The separation is now:
If you need to spit out dynamic views (i.e. view gets rendered on the server typically using Razor) then use ASP.NET MVC. Historically you could provide data but Web API is richer (it supports content negotiation).
If you need to provide data, then use ASP.NET Web API. You could fit in the view support but it is not meant for it.
I can see these will be joined together as ASP.NET web stack in the future versions (not the upcoming release).

Microsoft ASP .NET Web API, MVC 4 and SPA Architecture

Microsoft recently released MVC 4 Beta, which has these new very nice features like Web API and SPA. And as always Microsoft's demos do not demonstrate best practices from software design prospective. For example, using DbController which is tightly coupled to EF.
It seems for me that SPA and Web API go hand-by-hand in modern ASP .NET app.
I would like to hear any suggestions about structuring MVC 4-based solution, which is going to apply these new technologies like Web API and SPA.
For example, is it a good practice to separate Web API project with it's own controllers out of base MVC4 project or not. How to deal with SPA and not to use DbController in order to keep data persistence separately? What's going to be a main role of regular MVC4 app and especially Razor views?
Any other thoughts or suggestions are highly appreciated.
On separation of MVC4 + Web API: imho (as always) it depends on your concrete project.
Regarding EF: you should definitely not return EF Entities but return your own DTOs instead.
The role of MVC razor views could be rendering partial views you dynamically load from the client. You also could do some stuff like conditional loading of CSS / JS etc. for the Index page being loaded initially.
I think it's a good idea to keep the API in a separate web site project from your SPA/web site, as you can run in to problems with greedy routes.
Definitely keep your data access separate and loosely coupled.

Incorporating MVC functionality in an existing ASP.net project

We have an intranet system developed using asp.net webforms. We are kind of planning to partly incorporate mvc and such a scenario is as follows,
We would like to generate html documents using mvc (using razor view engine) where the inputs are going to come from a normal asp.net webform (from a form button click or so)
Some pointers or references to tutorials on running these 2 scenarios side by side would help a lot.
ASP.Net MVC and WebForms postbacks don't mix; the only way to do this would be to use <iframe>s (which is not a good idea).
I am not sure about your described implementation... however, you could start by re-writing some of your aspx pages using MVC views and just get all the existing code behind into a controller to minimize the creation of new code. You could do this one page at a time until all of your pages are MVC views. Good luck.

Classic ASP Pages Returned Within MVC3

Is it possible to directly return a Classic ASP web page as an Action Result etc? I have just inherited a stack of Classic ASP applications that are still being maintained and even extended.
I am looking to stop writing new Classic ASP code move to an MVC based setup (as that is the direction the department is going). Therefore I am looking for any options that don't require me to rewrite all the applications but allow me to slowly add features written in ASP.Net.
Ideally I would like to organise features around controllers etc and then return existing ASP pages as the result of Actions. I'd like the URL structure to look the same as a normal MVC site.
Any thoughts or advice? I know there are other posts on this. Haven't seen any that are trying to return ASP pages via Action Result etc.
Thanks
Graeme
Is it possible to directly return a Classic ASP web page as an Action Result etc?
No. The best you could do is redirect. If you are migrating some legacy classic ASP site to ASP.NET MVC you could do it progressively. You can start replacing pages one by one by introducing controllers, models and views. iframes could also be used as a temporary solution to interoperate between the two technologies during the migration.

Can ASP.net MVC 2 Project and CMS can be Combined together

I have developed project using Asp.net MVC 2.Now the content part of My site i don't want to build a Cms for that So my question is can i used any existing CMS developed in MVC2 so that The content part will be taken care of by the CMS
and Application part by developed project by me.
I have used CMS like Silverstripe which is quite easy which also provides ORM to develop application on their Sapphire engine which but developed in PHP.
If it is Combined then when writing Code i will write like this
[This just Sample Imaginary Code.I just want CMS to be easy]
<logo><Pick_up_from_CMS ID=logo></logo>
<menu><Pick_up_from_CMS ID=menu></menu>
<header><Pick_up_from_CMS ID=header></header>
<body>
<Pick_up_from_CMS ID=body>
<MY_Application_Logic ID=Logic1><!--This May be my Registration or Search form> -->
</body>
<footer><Pick_up_from_CMS ID=footer></footer>
It is possible, yes.
It won't be easy though. A lot of the Content Management Systems out there rely on their own set of ASP.NET WebForms user controls to provide content functionality.
If you're going to integrate a ASP.NET WebForms CMS with ASP.NET MVC 2, you're going to have to do your integration at the API level (assuming the CMS has an API).
That will allow you to retreive and insert your content in your controller without having to use any WebForms User Controls.

Resources