1

I looked around for quite a while but found no satisfying result. I want to use normal Razor Pages within .Net Core MVC. I used Angular before to enrich my Views for UI functionality. I do not need a SPA, I just want to use C# code for UI modification. Can I use Blazor in any way just to use C# code for client side interactions instead of Javascript/Angular (etc.) and still render most of my views on the server just like normal MVC?

Thanks in advance.

1 Answer 1

1

Yes, you can!

It is a well-documented scenario. Prerender and integrate ASP.NET Core Razor components

Basicaly you want to do something like that:

@using BlazorHosted.Client.Pages

<h1>@ViewData["Title"]</h1>

<component type="typeof(Counter)" render-mode="WebAssemblyPrerendered" />

@section Scripts {
    <script src="_framework/blazor.webassembly.js"></script>
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the reply. I am aware of the component scenario. But I was hoping to use "onclick","if this use that class" etc. anywhere in my razor view, without creating components. Is that possible in any way?
I'm unaware of that but it sounds like the whole point behind Blazor. A razor view where you can use c# logic client-side is a blazor (razor) component. Is ".NET Core MVC" a requirement? Have you considered using Blazor-Server?
Seems like I will go Blazor Server direction, although I am not very comfortable with a constant SignalR connection behind the scene. Thanks for the help.
There is nothing to worry about. I use Blazor in production since net core 3.1 and it is very reliable, not speaking about the massive productivity boost you will get. Good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.