小编use*_*651的帖子

关闭 Mudblazor 对话框

我在 Blazor 应用程序中使用 Mudblazor。我在 ValidSubmit 处理程序内的组件中有以下代码:

public async Task HandleValidSubmit()
{
    DialogService.Show<SavingDialog>("Saving Data");
    await Http.PostAsJsonAsync("api/Client/AddClient", CModel);

    //close the dialog here...
    //DialogService.Close(<need reference here>);
}
Run Code Online (Sandbox Code Playgroud)

打开DialogServiceSavingDialog也是一个组件。http 调用后,我想关闭对话框。我怎么做?DialogService.Close(DialogReference dialog)我可以在文档中看到。

如何获取对我打开的对话框的引用以便将其关闭?

dialog reference blazor mudblazor

6
推荐指数
1
解决办法
1万
查看次数

使用自动模式时,Blazor 应用程序在控制台中显示错误

我使用 Visual Studio 最新预览版和 .NET8 RC1 构建了一个新的 Blazor 应用程序,允许客户端和服务器交互组件。默认情况下,该应用程序有其默认渲染模式,我认为是 SSR。

为了切换到自动模式,我按照 Microsoft 的建议使用了以下代码(https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-8.0

所以我有这个:

    <Routes @rendermode="@RenderMode.Auto"/>
Run Code Online (Sandbox Code Playgroud)

在我的 App.razor 文件中。

尽管应用程序运行,但我在浏览器控制台中看到此错误:

Uncaught (in promise) Error: System.InvalidOperationException: Root component type 'BlazorApp9.Components.Routes' could not be found in the assembly 'BlazorApp9'.
   at Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer.<UpdateRootComponents>g__AddRootComponent|8_0(RootComponentOperation operation)
   at Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer.UpdateRootComponents(String operationsJson)
   at Microsoft.AspNetCore.Components.RenderTree.WebRenderer.WebRendererInteropMethods.UpdateRootComponents(String operationsJson)
   at 
Run Code Online (Sandbox Code Playgroud)

如果我使用 RenderMode.Server,我不会看到此错误。

我没有对 Visual Studio 提供的模板更改任何代码。

有任何想法吗?

blazor .net-8.0

6
推荐指数
1
解决办法
1120
查看次数

从 Blazor 应用程序中的 WEB API 返回数据

考虑以下两段代码。两者都将数据返回到 Web API Get 调用。两者都返回一个项目列表。两者都有效。第一个取自 Visual Studio 入门 Blazor Wasm 应用程序。第二个来自在线教程。tblTitles 是远程数据库中的一个表,通过 _dataContext 访问。

应该使用其中哪一个,为什么?或者也许一个更适合特定情况?

    [HttpGet]
    //First method:
    public IEnumerable<TitlesTable> Get()
    {
        var titles =  _dataContext.tblTitles.ToList();
        return titles;
    }

    //Second method:
    public async Task<IActionResult> Get()
    {
        var titles = await _dataContext.tblTitles.ToListAsync();
        return Ok(titles);
    }
Run Code Online (Sandbox Code Playgroud)

c# blazor webapi

5
推荐指数
2
解决办法
6033
查看次数

Blazor 输入无线电

当我们在InputRadioGroup中时,如何让单选按钮默认选中?这似乎不起作用:

<InputRadio class="mr-1" Name="Selected" Value="@("General")" checked="checked"></InputRadio>
Run Code Online (Sandbox Code Playgroud)

radio-group blazor

5
推荐指数
1
解决办法
8268
查看次数

Android BLE 广告失败,错误代码为 1

我有一个示例应用程序,它使用 BLE 来宣传一些数据。但是,我的广告失败并显示错误代码 1。错误代码 1 基本上意味着有效负载大于广告数据包允许的 31 个字节。但是从我的代码中,我可以看到有效载荷小于 31 个字节。问题出在哪里?

一些建议关闭设备名称广告,因为长名称会占用空间。我也这样做了。

private void advertise(){
        BluetoothLeAdvertiser advertiser =         BluetoothAdapter.getDefaultAdapter().getBluetoothLeAdvertiser();
    AdvertiseSettings settings = new AdvertiseSettings.Builder()
            .setAdvertiseMode( AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY )
            .setTxPowerLevel( AdvertiseSettings.ADVERTISE_TX_POWER_HIGH )
            .setTimeout(0)
            .setConnectable( false )
            .build();
    ParcelUuid pUuid = new ParcelUuid( UUID.fromString( getString( R.string.ble_uuid ) ) );
    //ParcelUuid pUuid = new ParcelUuid( UUID.randomUUID() );


    AdvertiseData data = new AdvertiseData.Builder()
            .setIncludeDeviceName(false)
            .setIncludeTxPowerLevel(false)

            .addServiceUuid( pUuid )
            .addServiceData( pUuid, "D".getBytes() )
            .build();
    advertiser.startAdvertising( settings, data, advertisingCallback );
}
Run Code Online (Sandbox Code Playgroud)

我希望这会宣传数据“D”,而不是因错误代码 1 而失败。

android bluetooth bluetooth-lowenergy

3
推荐指数
1
解决办法
1195
查看次数