标签: blazor-webassembly

BlazorWebAssembly GetFromJsonAsync 未序列化子集合

问题是,为什么当我使用 HttClient .GetFromJsonAsync 从客户端调用 api 时,实体没有子集合?我从浏览器调用 api,JSON 文本有集合,但在对象上没有。

\n

这是我的实体的代码:

\n
using System.Collections.Generic;\nusing System.ComponentModel.DataAnnotations.Schema;\n\nnamespace excelnobleza.shared.Models.Tablas.Produccion\n{\n    [Table("Lineas")]\n    public class Linea\n    {\n        public int Id { get; set; }\n        public string Nombre { get; set; }\n        public string Responsable { get; set; }\n        public string EmailResponsable { get; set; }\n        public virtual ICollection<Maquina> Maquinas { get; } = new HashSet<Maquina>();\n        public override string ToString() => this.Nombre;\n    }\n\n    public class Maquina\n    {\n        public int Id { get; set; }\n\n        [Required(ErrorMessage = "El nombre …
Run Code Online (Sandbox Code Playgroud)

c# .net-core blazor blazor-webassembly

0
推荐指数
1
解决办法
1074
查看次数

如何修复 Blazor WASM 内存访问越界错误?

启动了一个新的 Blazor WebAssembly 项目(Windows 10,Visual Studio 2019),尝试从服务器端通过 HttpClient 获取一个简单的列表。

错误:

00755c3a:0xa3a0 Uncaught (in promise) RuntimeError: memory access out of bounds
    at malloc (<anonymous>:wasm-function[359]:0xa3a0)
    at monoeg_malloc (<anonymous>:wasm-function[161]:0x3c71)
    at stack_frag_new (<anonymous>:wasm-function[2019]:0x59758)
    at add_frag (<anonymous>:wasm-function[1430]:0x3ccf2)
    at interp_exec_method (<anonymous>:wasm-function[1120]:0x2f609)
    at interp_runtime_invoke (<anonymous>:wasm-function[5655]:0xf7391)
    at mono_jit_runtime_invoke (<anonymous>:wasm-function[5109]:0xddb3d)
    at do_runtime_invoke (<anonymous>:wasm-function[1410]:0x3ba85)
    at mono_runtime_try_invoke (<anonymous>:wasm-function[418]:0xcfdb)
at mono_runtime_invoke (<anonymous>:wasm-function[1610]:0x44b39)
Run Code Online (Sandbox Code Playgroud)

服务器端(正确返回):

    [HttpGet]
    public async Task<IEnumerable<UserDetailsRM>> Get()
    {
        var users = await UserService.GetUsers();
        return users;
    }
Run Code Online (Sandbox Code Playgroud)

客户端:尽管得到了结果,但不渲染任何东西。

<div class="userListWrapper">
        @if (Users != null)
        {
            <table class="table table-borderless" style="font-size:12px; font-family:arial; height: 
                500px; …
Run Code Online (Sandbox Code Playgroud)

.net c# .net-core blazor blazor-webassembly

0
推荐指数
1
解决办法
1975
查看次数

在不相关的组件上调用 OnSetParameterAsync

我目前正在开发一个使用 Blazor WebAssembly 作为前端框架的项目,但是,我认为我在状态管理方面遇到了一些复杂情况。这个问题发生在一个大型复杂的解决方案中,因此我重新创建并简化了它,这样我就可以在这里简洁地描述它,而不会显得臃肿。

我有一个包含两个组件的页面:朋友列表和关注者列表,每个组件都有一个按钮来切换按升序或降序对列表进行排序。

如果我重写并在FollowerList组件内部的OnParametersSetAsync上放置一个断点,然后单击FriendList组件的排序按钮,它会命中我在FollowerList组件上设置的断点。

我的印象是,只有当提供给该组件的属性发生更改或其状态发生更改时,才会在该组件上调用OnParametersSet/Async。在下面的代码中,您可以看到我有两个单独的列表,一个被馈送到一个组件,一个被馈送到另一个组件,所以我不确定如何在未触及的组件上触发此方法......

因此我的问题是:为什么它会在不相关的组件上遇到断点?这是故意行为吗?

页面预览

索引页,包含两个列表

索引剃刀

@page "/"
<button value="Sort Friends" @onclick=SortFriends>Sort Friends</button>
<FriendList Friends=SortedFriends />

<button value="Sort Followers" @onclick=SortFollowers>Sort Followers</button>
<FollowerList Followers=SortedFollowers />
Run Code Online (Sandbox Code Playgroud)

Index.cs(隐藏代码)

using StateManagementTest.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace StateManagementTest.Pages
{
    public partial class Index
    {
        public List<Friend> MyFriends { get; set; }
        public List<Friend> SortedFriends { get; set; }

        public List<Follower> MyFollowers { get; …
Run Code Online (Sandbox Code Playgroud)

c# blazor blazor-client-side blazor-webassembly

0
推荐指数
1
解决办法
654
查看次数

完全在 Blazor Webassemble 中完成 setInterval 的有效替代方案是什么?

我在想这样的事情:

protected override async Task OnInitializedAsync() {
  //...
  RunMeEndlesslyWithoutAwait();
  //...
}
protected async Task RunMeEndlesslyWithoutAwait() {
  while (online) {
    //... do stuff
    await Task.Delay(60000);
  }
}
Run Code Online (Sandbox Code Playgroud)

但我不确定这是否是最充分的。

setInterval(...)使用 Blazor WebAssembly 的JS 函数是否有任何已知的最佳/有效方法?

c# setinterval blazor blazor-webassembly

0
推荐指数
1
解决办法
1987
查看次数

Blazor 中的文本或数字框中自动突出显示

我处于 Blazor 的初级水平。我需要知道当单击文本框或数字框时,文本框或数字框中的文本应根据下图自动突出显示。

在此输入图像描述

我怎样才能使用 blazor 做到这一点?

blazor blazor-webassembly mudblazor

0
推荐指数
1
解决办法
1241
查看次数

在将结果返回到控制器之前是否可以过滤存储库模式获取的数据?

该项目是 C# VS-2022 Blazor WASM,具有用于数据库 API 的 REST-API 存储库模式。

每当我在存储库函数中使用Where()条件时,我都会收到编译错误。

错误 CS1061“DbSet”不包含“GetAwaiter”的定义,并且找不到接受“DbSet”类型的第一个参数的可访问扩展方法“GetAwaiter”(您是否缺少 using 指令或程序集引用?)

例如在存储库函数中:

returnRecs = (await appDbContext.MOTrip).Where(r => (r.UID_CUSTOMER == uidModel));
Run Code Online (Sandbox Code Playgroud)

我尝试在存储库中进行过滤的原因是因为数据库表“MoTrip”包含数十万条记录。我认为(await appDbContext.MOTrip)在控制器中获取所有记录并遵循各种过滤条件将是浪费。

在此问题中提出的情况下,按 CUSTOMER 进行过滤将是存储库功能获取的记录数的 1/100。

欢迎您的回答和评论。谢谢约翰。

c# repository-pattern blazor-webassembly

0
推荐指数
1
解决办法
331
查看次数

如何在 Blazor 中创建计时器组件并从组件或其他页面外部启动它

如何在 Blazor 中创建计时器组件并从组件或其他页面外部启动它。我的组件代码如下:

@using LosacoWeb.Shared.Enumes
@using System.Timers
@implements IDisposable

@if (BlnVisiblaState == true)
{
    <section>

        <div class="container">
            <div class="row">
                <div class="col-lg-8 offset-lg-2">
                    <div>

                        <div class="alert shortcode_modules" style="border-color:lightblue;border-style: solid;border-width: thin;padding: 5px;margin: 5px 10px;border-radius: 5px;" role="alert">
                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                <span class="icon-close" aria-hidden="true"></span>
                            </button>
                            <div class="modules__title">
                                <h3 dir="rtl" style="float:right;">@MessageTitle</h3>
                            </div>

                            <div class="modules__content">
                                @if (message == MessagePanelColor.primary)
                                {
                                    <div class="alert alert-primary" role="alert">
                                        <strong>@MessageShortDescription !!!</strong>@MessageBuddyLongDescription
                                        @*<button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                                <span class="icon-close" aria-hidden="true"></span>
                                            </button>*@
                                    </div>
                                }
                                @if (message == MessagePanelColor.secondary)
                                {
                                    <div class="alert …
Run Code Online (Sandbox Code Playgroud)

blazor blazor-webassembly

-1
推荐指数
1
解决办法
70
查看次数