Razor Client Library page callback to parent Blazor Server page - url

I have built a Blazor server app which utilises a Razor Class Library to host razor pages. The app works perfectly when I call any razor page in the RCL from the NavMenu in the Blazor Server app.
However, I'm trying to figure out how to return to a page in the Blazor Server app from a link in the RCL Razor page or Controller.
Could anyone advise me on how to do this?

Related

Integrating VUE to the exsiting mvc razer page application

I have an existing MVC razor page application. From the home page that is implemented in MVC razer page when I click on login button other pages I need to implement in the VUE JS . How can do that ? How do I put link to the vuejs component.
If you want the login button can link to a vue component, it should be in a Vue Instance, then use vue router to do the redirection.
But if you want to have a single page application, and mixing asp.net mvc views with vue.js is not a good idea. Eventually, you will face many problems. It could be better implement web api services with dotnet core and vue as the client

How to enable/use/configure WebAssembly Blazor in existing .NET MVC Project?

I have a web application that is written in .net core MVC, a standard, "old school" web application using model/view/controller pattern. In this app I have a few complex forms which change based on user selection. Different elements load based on what user selected in the first few drop down lists. Currently I use Vue.js to successfully build such an interface. So basically I do not have a SPA app but I sporadically use Vue.js throughout my app when there is a need for a complex front end interface.
Now that client side WebAssembly Blazor is officially out, I would like to replace my complex forms written in vue.js with a Blazor based code. I've found the post that explains how to do this with server side Blazor here but I can't find anything with regards to WebAssembly version of it.
Has anyone managed to integrate client side - web assembly Blazor into an existing MVC project? If so how?
To setup Blazor WASM to an existing project you need to :
Add a reference to the Blazor WASM project in your ASP.Net Core project
Add package reference to Microsoft.AspNetCore.Components.WebAssembly.Server
Add UseBlazorFrameworkFiles() in your middleware pipeline
Add UseStaticFiles() in your middleware pipeline
Add MapFallbackToFile to endpoints pointing to your Blazor WASM index.html
public void Configure(IApplicationBuilder app)
{
if (Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage()
.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error")
.UseHsts();
}
app.UseHttpsRedirection()
.UseBlazorFrameworkFiles()
.UseStaticFiles()
.UseRouting()
.UseAuthentication()
.UseAuthorization()
.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapFallbackToFile("index.html");
});
}
I have this working and it's really made my week.
Firstly, update or convert your MVC project to .Net 5.0.402.
It MAY work on an earlier version but I haven't tested it.
To your MVC solution, add a blazor web assembly app project.
This is the web assembly components project.
On the MVC view, at the place you wish to render your blazor component add:
#using myawesomewasmprojectnamespace.Pages
<component type="typeof(Counter)" render-mode="WebAssemblyPrerendered"/>
<script src="_framework/blazor.webassembly.js"></script>
The '#using' declaration refers to the blazor web assembly app project, Pages directory.
The 'typeof(Counter)' type refers to the Counter.razor component in the default blazor web assembly app project, visual studio supplies.
This may of course be swapped for the final design component.
In the MVC project's _Layout.cshtml, or wherever the <head> tag of the MVC view is, include in the <head> tag for every page with a blazor component in it:
<base href="/"/>
Add the 'Microsoft.AspNetCore.Components.WebAssembly.Server' package to your MVC project.
Add a reference to the blazor web assembly app project, in your MVC Dependencies, project references.
In the MVC apps Startup.cs, 'public void Configure(IApplicationBuilder app, IWebHostEnvironment env)' method, add the following:
app.UseBlazorFrameworkFiles();
In the blazor web assembly app project, Program.cs file, comment out the following line to stop the application looking for a '<div id="app"></div>'
//builder.RootComponents.Add<App>("#app");
Finally, delete the favicon from the blazor web assembly app project's wwwroot directory as it will clash with the MVC one.
This then adds the 'Counter' component to your MVC view.
To add a different component to a different view, insert it with:
#using myawesomewasmprojectnamespace.Pages
<component type="typeof(Myawsomecomponentnamecompletelydifferentfromanymvccontrolleroractionname)" render-mode="WebAssemblyPrerendered"/>
<script src="_framework/blazor.webassembly.js"></script>
And start your blazor component with:
#page "/myawsomecomponentnamecompletelydifferentfromanymvccontrolleroractionname"
I'm so chuffed to get this working, as I've been trying for ages.
If you can't get it working, please message me and I'll try to answer any questions.

Embedding aspx website page in MVC view

I have normal ASP.NET MVC application , in which I want embedd aspx application . I have geomedia portal published on server and want to embed that portal on MVC application

Why MVC in Durandal VS project template?

All the action is client side in a SPA app. The Visual Studio Durandal and Hot Towel project templates both serve the SPA out of an ASP.NET MVC application.
What, if anything, does the ASP.NET MVC infrastructure bring to the party? As far I can see all it does is make it hard to serve a WCF Web Service (ajax enabled) out of the project web.
Yet both of the project templates are set up like this. What have I missed?
As a matter of fact, ASP.NET MVC in this template is not necessary. All it does is serve the initial Razor template for the SPA and provides you with the bundling and optimization support of all the client side javascript resources for the application so that when you deploy your application you don't end up with gazillions of HTTP requests from the client to fetch all the .js crap necessary for the application to work. Of course you could perfectly fine have used the bundling feature outside of ASP.NET MVC in a simple and plain ASP.NET web application.
What, if anything, does the ASP.NET MVC infrastructure bring to the party?
See the documentation:
Hot Towel builds on the familiar and powerful ASP.NET MVC structure.
App_Start
Content
Controllers
Models
Scripts
Views
As far I can see all it does is make it hard to serve a WCF Web Service (ajax enabled) out of the project
You can't just right-click your project and add a new WCF Service?

MVC - Opening an asp.net page from the controller

I don't know if this is possible.
Can I have a mvc controller open a popup asp.net page? The asp.net page is within the mvc application, it's basically to run a crystal report viewer.
What happens just now is the mvc view loads and lists reports, then when a report is clicked it launches and exports to pdf. We now want this embedded in a web page instead of exporting to pdf(for various reasons one being no local download of the pdf report).
So sfter reading up i came across the solution to use a folder within the mvc app and use a webform in there. Now I'm trying to find how to open the .aspx pop-up from the controller where the report viewing is initiated.
Does that make any sense.
Any links/help is appreciated
Controllers in ASP.NET MVC are not supposed to open popups. You could do this using javascript inside the view. The window.open javascript function could be helpful:
window.open('/report.aspx', 'report');

Resources