blazor in admin (plugin)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
1 年間の 前
Hello.

Have anyone managed to use blazor inside a plugin in admin panel for nopCommerce?

I've tried registering blazor the same way as this guide, but for some reason i end up with a 404 on _framework/blazor.server.js  no matter what i do.
1 年間の 前
This might help you. You can check this full message thread nopCommerce with Blazor
1 年間の 前
Rashed Khan wrote:
This might help you. You can check this full message thread nopCommerce with Blazor


Thanks, but sadly that is not working. I think the issue is staticfiles. The blazor.server.js file cant be found if i navigate to https://localhost:5001/_framework/blazor.server.js

But, in the post you linked he is mapping a fallback to a controller Blazor with action home. I dont know why he would do that. Cant see any controller named blazor in his example either
1 年間の 前
I've gotten a bit further.

I have added the following right into (ill move it to custom startups later when its working).

ApplicationBuilderExtensions.cs
At the end of UseNopStaticFiles i added
application.UseStaticFiles();

and inside UseNopEndpoints:
public static void UseNopEndpoints(this IApplicationBuilder application)
        {
            //Execute the endpoint selected by the routing middleware
            application.UseEndpoints(endpoints =>
            {
                //register all routes
                EngineContext.Current.Resolve<IRoutePublisher>().RegisterRoutes(endpoints);
                endpoints.MapBlazorHub();
            });
        }

And in ServiceCollectionExtensions.cs i added
Below this: services.AddRazorPages();
I added services.AddServerSideBlazor();

In home.cshtml i added:
@(await Html.RenderComponentAsync<Nop.Web.Views.Shared.Component.TestComponent>(RenderMode.ServerPrerendered))

In _ViewImports.cshtml i added:
@using System.Net.Http
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using System.IO

In _Root.cshtml i added:
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

and inside <head>

<base href="/" />

and below </html> i added
<!script src="_framework/blazor.server.js"></!script>

In TestComponent.razor i added:
<div class="card-header">  
  
    <h3>DataComponent</h3>  
    <button @onclick="Getdata" class="btn btn-dark">Click to GetData    </button>  
</div>  
<div class="card-body">  
    <br />  
    <div class="@style">@Data </div>  
</div>  
  
@code {  
    [Parameter]  
    public string Data { get; set; } = string.Empty;  
    [Parameter]  
    public string style { get; set; }  
    private void Getdata()  
    {  
        Data = "I am Working";  
        style = "badge-success";  
    }  
}

I am now able to see and navigate to https://localhost:5001/_framework/blazor.server.js

but i get the following issue now:
Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException: The request matched multiple endpoints. Matches:

Blazor initializers
Blazor initializers
Nop.Web.Controllers.CommonController.GenericUrl (Nop.Web)
1 年間の 前
How did you go with this?

Blazor is a SPA framework. Are you looking at totally replacing the front end for customers and you the NOP web api? Or are you just wanting to use Blazor as components?

If it is just Blazor as components on a page, then I have a solution that I can share with you that works with MVC and should work with NOP.
1 年間の 前
Hello. I did not finish this sadly.

I only wanted to use blazor in admin and only in plugins.

As far as i know Blazor does not need to be a full spa. You can use it for some parts of a mvc project with blazor components.

I stopped at the issue with routing as mentioned in my previous post.
1 年間の 前
GraGra33 wrote:

If it is just Blazor as components on a page, then I have a solution that I can share with you that works with MVC and should work with NOP.


Did would be awesome! :D
1 年間の 前
Let me try and will get back to you. The trick is starting up the Blazor WASM rendering engine. I am not sure if it can be done from the pluging as it is part of the WebApplicationBuilder.
1 年間の 前
GraGra33 wrote:
Let me try and will get back to you. The trick is starting up the Blazor WASM rendering engine. I am not sure if it can be done from the pluging as it is part of the WebApplicationBuilder.



Hello! Have you had a chance to test this? :)
1 年間の 前
Hi guys!
Is there an update on this?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.