Aspnetcore: Combine MVC razor pages with Blazor pages

Created on 2 Jul 2018  路  7Comments  路  Source: dotnet/aspnetcore

I guess lots of us are now developing MVC applications and at some point want to convert those to Blazor.

I think I would be convenient if Blazor supports some sort of migration path by making it possible to combine Blazor and MVC pages. This will make it possible to gradually migrate your app, page by page.

Currently if there is no route registered with a Blazor component, Blazor will throw an exception, if the router would then try to just load the url I think we are almost there.. Would this be feasible?

I've got some sort of workaround running with iframes in a razorpage loading the MVC page, but that just feels dirty..

All ideas welcome..

area-blazor

Most helpful comment

Ok. I think I figured this out (with the help of the gitter guys). If you do this in your startup:

app.Map("/blazor", child => { child.UseBlazor<Client.Program>(); });

and modify your blazor index.html like this:

<base href="/blazor/" />

It works like I intend, I'm able to link and navigate from blazor to mvc pages that not reside in the /blazor folder.
I'll have to do more testing if everything works.. but I guess so..

All 7 comments

Yes, good point. Especially when BLAZOR will support server-side(websockets using signal-r), then we will not need MVC at all...

I was also thinking about adding Blazor to my ASP.NET Core MVC application but who should be responsible for rendering common page elements like main application menu, footer, etc.? Probably we have to do this in MVC and Blazor. I think in non trivial web application serious refactoring will be necessary to reuse the same code in MVC and Blazor. There is yet another problem - application state. We should save/restore state before/after each transition between both technologies. Currently Blazor is not good for SEO - it is not acceptable for most people.

I'm not sure I still want to combine these two technologies in one application. Instead I would like to have server side rendering aspnet/AspNetCore#5464 (do not confuse this with Blazor working on the server as demonstrated recently by Steve!)

Ok. I think I figured this out (with the help of the gitter guys). If you do this in your startup:

app.Map("/blazor", child => { child.UseBlazor<Client.Program>(); });

and modify your blazor index.html like this:

<base href="/blazor/" />

It works like I intend, I'm able to link and navigate from blazor to mvc pages that not reside in the /blazor folder.
I'll have to do more testing if everything works.. but I guess so..

@floreseken any update on the testing of this?

Yes, works fine.

please tell me how to use blazor page in asp.net with mvc

@monu3012 I wrote up how to get server-side Blazor components working on an MVC app here https://stackoverflow.com/a/56245667/1879019, which might give you some ideas.

Was this page helpful?
0 / 5 - 0 ratings