Skip to content

[Blazor] Support for wasm blazor integration with existing mvc app #12061

@stavroskasidis

Description

@stavroskasidis

Is your feature request related to a problem? Please describe.

While I was experimenting on embedding blazor client side (wasm) in an existing mvc app, it seems that it is close enough to be easily implemented, however some changes are needed to have this scenario supported (in which I am very interested).

For example, the following scenario kinda works:

Having 2 projects, an mvc core app and a blazor clientside app

Mvc App (references the blazor client project)

//Startup.cs
app.UseClientSideBlazorFiles<Client.Startup>();
<!-- Shared/_Layout.cshtml -->
<head>
  <!-- ... -->
  <base href="~/" />
  <!-- ... -->
</head>
<body>
   <!-- ... -->
   <script src="_framework/blazor.webassembly.js"></script>
</body>
<!-- Home/Index.cshtml -->
<counter>Loading ...</counter>

@*Or using prerendering*@
@*<counter>@(await Html.RenderStaticComponentAsync<Counter>())</counter>*@

Blazor Client App

public class Startup
{
        public void ConfigureServices(IServiceCollection services)
        {
        }

        public void Configure(IComponentsApplicationBuilder app)
        {
            app.AddComponent<Counter>("counter");
        }
}

This works fine for the Index.cshtml page however if you navigate to an other page (or add another component) you get an exception like this

WASM: Error: Could not find any element matching selector 'counter'.

Describe the solution you'd like

Full support for embedding blazor client-side (wasm) in existing MVC applications.

IMHO it will help with adoption tremendously and is a very nice alternative for people who do not want to use server-side blazor to do the same thing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions