小编Tob*_*obi的帖子

How can I pass a read only collection to a blazor component?

I have created a simple Blazor component (.NET Core 3.1, Blazor server apps) with a public parameter:

    [Parameter]
    public IReadOnlyCollection<Resource> Services { get; set; }
Run Code Online (Sandbox Code Playgroud)

I fill this parameter from a .cshtml page:

    <component type="typeof(ActivityView)" render-mode="ServerPrerendered" param-Services="Model.Services" />
Run Code Online (Sandbox Code Playgroud)

The model property has the same type:

    public IReadOnlyCollection<Resource> Services { get; set; }
Run Code Online (Sandbox Code Playgroud)

When the instance of services is a ReadOnlyCollection(Resource), the blazor page directly runs into the following error on the client side:

Error: The list of component records …

blazor

5
推荐指数
0
解决办法
678
查看次数

将 blazor 组件包含到 MVC 视图中(.NET Core 3 Preview #5)

我正在尝试将 blazor 组件包含到我的 MVC 应用程序中,但端点路由的某些内容似乎不太好。

我有一个 razor 页面(在 pages/example.cshtml 中)和一个带有视图(在 Views/Home/Index.cshtml 中)的默认控制器(在 Controllers/Home 中)。

开...

  • [本地] -> 索引视图,Blazor 有效
  • [local]/Home -> 索引视图,Blazor 工作
  • [local]/Example -> 示例页面,Blazor 有效
  • [local]/Home/ -> 索引视图,Blazor 不起作用
  • [local]/Home/Index -> 索引视图,Blazor 不起作用

脚本调试器说: HTTP404:未找到 - 服务器未找到与请求的 URI(统一资源标识符)匹配的任何内容。(XHR)POST - https://localhost:44342/Home/_blazor/negotiate

我在启动文件中尝试了不同的东西,但无论我尝试过什么,我都无法让它工作。

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddRazorPages();
        services.AddServerSideBlazor();
        services.AddSingleton<WeatherForecastService>();
        //services.AddControllersWithViews(o => o.EnableEndpointRouting = false); -> does not change anything
        services.AddMvc(o => o.EnableEndpointRouting = false);
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else …
Run Code Online (Sandbox Code Playgroud)

blazor

2
推荐指数
1
解决办法
407
查看次数

标签 统计

blazor ×2