Is it feasible to convert an single MVC razor view/page into a SPA? - asp.net-core

I currently have an ASP.NET Core MVC application with multiple pages with one particular page having a lot of hand-made javascript code and ajax requests. It's becoming quite hard to manage and I would like to move to a framework like Angular, React etc for this particular page only. It is feasible to convert a single MVC view to a SPA app and still keep the other pages? Does anyone have any references on this? Google is not being too helpful...

The simplest way I have found to do this is to use one of the SPA templates and then add the static pages around that.
Here's an an example project I have made that demonstrates the concept by adding a new Razor Page to the angular SPA template.
To do this for an already existing MVC/Razor Pages app I would suggest copying the following from an SPA template project to the MVC/Razor Pages app:
ClientApp
Controllers (SampleDataController.cs)
Views (Home, Shared)
npm_shrinkwrap.json
package.json
tsconfig.json
webpack.config.json
webpack.config.vendor.json
Startup.cs (copy the SPA things)
This is not an exhaustive list but should get someone most of the way.

Related

How should I embed Blazor server-side into an existed asp.net core project?

I made a blazor server-side project for submitting the form.
In spite of there is a tutorial of Microsoft about how to embed it in asp.net core(https://learn.microsoft.com/en-us/aspnet/core/blazor/components/integrate-components?view=aspnetcore-3.1). However, I am about to embed it not only in one website but also in some other. So this way is so troublesome.
There is another way by using Iframe. Whereas Iframe does not support CSS vh units well and it has some other limited(such as samesite attribute/cross-origin).
Is there any way to solve this? Thank you.
I suggest you could consider build it as an Templated components.
You could create a component library. And then you could use this template in each project.
Details, you could refer to this article.

Asp.Net core Individual User Authentication Login/Register Pages

I am new to Asp.net core razor pages. I am using asp .net core version 2.2, I am trying to make an application using Social Media authentication services. But the problem I am facing is the weird structure of asp .net core razor applications. I have already done the authentication things, but the problem I am facing is to find the Login and Registration pages. Where can we find them? What if we want to change the layout or something. What should we do for that?
Depending on how you implemented authorization, and based on the documentation :
You should be able to find the scaffolded views in the Areas\Identity's folder of your project or in the ~/Pages/ folder.
If you want to change the layout or something else, you can edit those views (customize) and/or create other ones.
Don't forget to generate the scaffolded views using :
From Solution Explorer, right-click on the project > Add > New Scaffolded Item
Hope it helps.
The default scaffolded Razor pages in ASP.NET Core are made using Partial Views. The default layout of the applicaton can be found in Pages/Shared/_Layout.cshtml.
Inside of this file there is a reference to Pages/Shared/_LoginPartial.cshtml , which contains the layout for the login page. The reference should be somewhere around line 35 in the _Layout.cshtml.
If you want to edit the way the default Razor pages look, this is where you do it.

MVC4 Web API - OK to delete all views/javascript?

Just created a new MVC4 Web API project - however I don't want any client-side for this, just the back-end to be referenced from other clients.
Is there any, sensible, reason that the default project template includes all of the javascript, views, etc?
Can they be removed without issue?
Default the web api project also contains the regular mvc stuff. If you do not intent to use the web api help pages (https://www.nuget.org/packages/Microsoft.AspNet.WebApi.HelpPage) or intend to develop a website part next to your api you can easily remove all views, scripts & statics.

Integrate Orchard CMS with MVC4 Website

I already have MVC4 website and that is to perform Searching (OPAC). Now, We have to integrate it with Orchard CMS. I have followed the procedures to add my existing solution into Orchard CMS solution. Everything is okay but I am not able to get the javascript to work with my view page.
Also, The default Orchard library to include js extensions ie, #Script.Require or #Script.Include also not recognised as intellisense feature in my view page.
When I use default MVC library to include the js like #Scripts.Render is not working as expected.
How can I make my custom javascript to work my page.
Help me to identify the problem.
Thanks

Can we use Razor on an existing ASP.NET 4 website?

Is it possible to use Razor on an existing ASP.NET 4 website?
Yes, you can use Razor with an existing ASP.NET WebSite. Simply open your website using the WebMatrix tool and start adding CSHTML files.
One caveat is that if your website is using WebForms controls the WebMatrix tool will not provide any help working with them in existing aspx pages. Additionally, Razor does not support WebForms so you will not be able to add something like <asp:GridView> to a CSHTML file.
You shouldn't even need to open the site in Web Matrix if you already have VS2010 and MVC 3 (which includes the Visual Studio tools for building ASP.NET Razor websites) installed. Installing MVC 3 makes the libraries required for developing Razor pages available, even to existing web applications.
See:
http://www.asp.net/webmatrix/tutorials/program-asp-net-web-pages-in-visual-studio
You don't need to create a new Web Pages site (as per the instructions). You can just open up an existing web site, right click the site's root folder, click add item and you should see "Web Page (Razor)" as an option.
Inellisense and debugging works in the Razor pages just like the Web Forms pages
As stated above, keep in mind that ASP.Net Web Pages (Razor) and ASP.Net WebForms are really different platforms, and the reusable components of each can not (or at least should not) be used
marcind is correct, if you want to open your existing ASP.NET website in WebMatrix and work on it from within the tool. If, on the other hand (or in addition to), you want to use Razor syntax in your site and stay within VisualStudio, check out this article: http://weblogs.asp.net/rashid/archive/2010/07/10/use-razor-as-asp-net-mvc-viewengine.aspx
There are four things you need to do:
Add References to the Razor assemblies installed with WebMatrix. These can be found at C:\Program Files\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies
Create a custom ViewEngine class, a View class that inherits from IView (not that hard, check out the source in the article above)
Add your new ViewEngine in Global.asax Application_Start()
ViewEngines.Engines.Add(new RazorViewEngine(("cs"));
Create your view pages with a .cshtml extension, instead of .aspx
There are a few steps here, but it's quick work, and the source from the article above will get you a long way there.