小编Jac*_*kal的帖子

如何在 blazor 中渲染 razor 组件内的内容?

使用标签助手,您可以定义一个可以轻松编写内容的区域。例如,我可以制作一个引导卡标签助手,并轻松地在卡体标签内渲染我想要的任何内容。使用剃须刀组件我怎样才能实现这一目标?

<div class="card">
    <div class="card-header"></div>
    <div class="card-body">

        @*render content here*@

    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

blazor-server-side asp.net-blazor

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

Entity Framework Core 如何进行任何异步?

    public async Task<bool> IsParagemOnGoingAsync(int registoId)
    {
       return await _context.ParagensRegistos
           .Where(pr => pr.RegistoId == registoId)
           .Any(pr => pr.HoraFim == null);
    }
Run Code Online (Sandbox Code Playgroud)

我怎样才能使这个异步?我在谷歌上找不到任何东西...

编辑

我知道 AnyAsync();

我尝试了多次,但从来没有智能感知来添加引用。

c# entity-framework-core

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

Asp .Net Core 为什么即使用户未经过身份验证也会调用我的授权处理程序?

我有一个问题,如果我手动转到登录页面之后的页面,我的策略句柄之一会出现异常,因为它找不到索赔。

为什么会发生这种情况,而不是将用户重定向到登录页面,因为他没有经过身份验证?我什至设置了身份验证方案,因为我的所有页面都有

[Authorize("scheme"), Policy = "policy"]
Run Code Online (Sandbox Code Playgroud)

这是我的整个启动代码

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddAuthentication()
         .AddCookie("ProductionAuth", options =>
         {
             options.ExpireTimeSpan = TimeSpan.FromDays(1);
             options.LoginPath = new PathString("/Production/Index");
             options.LogoutPath = new PathString("/Production/Logout");
             options.AccessDeniedPath = new PathString("/Production/AccessDenied/");
             options.SlidingExpiration = true;
         })
        .AddCookie("AdministrationAuth", options =>
        {
            options.ExpireTimeSpan = TimeSpan.FromDays(1);
            options.LoginPath = …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core

4
推荐指数
1
解决办法
7060
查看次数

防伪令牌 Axios Asp .Net Core

嗨,我可以像这样使用 vue js axios 将帖子发送到 Asp .NET Core 2.2 中的控制器

                axios({
                    url: '/Parametros/Create',
                    method: 'post',                    
                    ContentType: 'application/json',
                    data: formData                        
                })
Run Code Online (Sandbox Code Playgroud)

但是为了这个工作,我必须从我在控制器中的动作中删除

[ValidateAntiForgeryToken]
Run Code Online (Sandbox Code Playgroud)

此外,令牌在剃刀页面中作为输入生成

<input name="__RequestVerificationToken" type="hidden" value="CfDJ8GwWLSmGzLVOqfs-yISjocyQshOjT98BeCqxo14sO91JGUZPe_IstyK9DWZyu0rCr0bxdx3lBlwminvxm7q0zXVWcUkAZIH8NwKDYGdNCiY-Z_BgMzLt_1PyNEHxfpmTouJgMu3il8N4fMjbI0ohwElXGK-eVLXGuzj_J5N_uQ3A4f-9ijmTKGk8p3BC7hrB1A">
Run Code Online (Sandbox Code Playgroud)

我试过

axios({
    url: '/Parametros/Create',
    method: 'post',
    headers: { 
        "__RequestVerificationToken": $('input[name="__RequestVerificationToken"]').val();
    }                    
    ContentType: 'application/json',
    data: formData                        
})
Run Code Online (Sandbox Code Playgroud)

axios({
    url: '/Parametros/Create',
    method: 'post',                  
    ContentType: 'application/json',
    data: {
        "__RequestVerificationToken": $('input[name="__RequestVerificationToken"]').val(),
        formData                        
    }
})
Run Code Online (Sandbox Code Playgroud)

没有工作,我不断收到糟糕的请求......使用 ajax 第二种方法可以正常工作,但 axios 不行。我该如何处理?

javascript axios vuejs2 asp.net-core-2.2

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

Bootstrap 4 个垂直选项卡和右侧的内容

我正在尝试使用引导程序选项卡制作表单向导。布局很简单

垂直选项卡,如侧边栏菜单和右侧的内容

|   Tab1  |                      |
|   Tab2  |       Content        |
|   Tab3  |                      |
Run Code Online (Sandbox Code Playgroud)

为此,我使用了 bootstrap 网格,但有一个问题,如果我减小浏览器大小,内容将位于选项卡下。

尽管浏览器大小不同,有没有办法将内容保留在选项卡旁边?

<div class="container-fluid">
    <div class="row">
        <div class="col-md-2">
            <div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
                <a class="nav-link active" id="v-pills-home-tab" data-toggle="pill" href="#v-pills-home" role="tab" aria-controls="v-pills-home" aria-selected="true">Home</a>
                <a class="nav-link" id="v-pills-profile-tab" data-toggle="pill" href="#v-pills-profile" role="tab" aria-controls="v-pills-profile" aria-selected="false">Profile</a>
                <a class="nav-link" id="v-pills-messages-tab" data-toggle="pill" href="#v-pills-messages" role="tab" aria-controls="v-pills-messages" aria-selected="false">Messages</a>
                <a class="nav-link" id="v-pills-settings-tab" data-toggle="pill" href="#v-pills-settings" role="tab" aria-controls="v-pills-settings" aria-selected="false">Settings</a>
            </div>
        </div>
        <div class="col-md-10">
            <div class="tab-content" id="v-pills-tabContent">
                <div class="tab-pane fade show active" id="v-pills-home" role="tabpanel" aria-labelledby="v-pills-home-tab"> …
Run Code Online (Sandbox Code Playgroud)

html twitter-bootstrap

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

对按键做出反应仅执行一次 setTimeout

当用户完成输入、计时器基本完成时,我需要运行一些东西。当用户键入时计时器将被重置,但一旦时间结束,它将根据用户键入的次数运行该函数

export default function SearchMovie() {
    var keyUpTimer = 0;
    const keyUpTimerDelay = 2000;


    const handleOnKeyUp = (event) => {
        clearTimeout(keyUpTimer);
        keyUpTimer = setTimeout(() => {
    
            console.log(input);
        }, keyUpTimerDelay);
    };


    return (
        <div className="search-container">
            <input
                type="text"
                className="input-text"
                onInput={(e) => setInput(e.target.value)}
                onKeyUp={handleOnKeyUp}
                placeholder="Type a movie to search..."
            />
        </div>
    );
}
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

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

如何在角色声明中存储多个角色?

claims.Add(new Claim(ClaimTypes.Role, string.Join(",", user.UserRoles.Select(ur => ur.Role.Nome))));
Run Code Online (Sandbox Code Playgroud)

但是如果我这样做

User.IsInRole("myRole")
Run Code Online (Sandbox Code Playgroud)

它返回 false

c# asp.net-core

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

Entity Framework Core 首次调用时速度太慢

我有大约 40 个实体,每次编译并运行我的应用程序后,第一次调用 DbContext 都会花费近 10 秒的时间。有没有办法让它运行得更快?

\n\n

这是当用户已经登录我的应用程序时我在第一次通话时所做的事情

\n\n

页面模型

\n\n
public class CreateModel : PageModel\n{\n    private readonly IToastNotification _toastNotification;\n    private readonly ICelulaService _celulaService;\n\n    public CreateModel(IToastNotification toastNotification, ICelulaService celulaService)\n    {\n        _toastNotification = toastNotification;\n        _celulaService = celulaService;\n    }\n\n    public IList<Celula> Celulas { get; set; }\n\n    public void OnGet()\n    {\n        Celulas = _celulaService.GetAutomated();\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

服务与接口

\n\n
public interface ICelulaService\n{\n    IList<Celula> GetAutomated();\n}\n\npublic IList<Celula> GetAutomated()\n{\n    return _context.Celulas\n         .Where(c => c.Automated)\n         .ToList();\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

该模型

\n\n
[Table("hCelulas")]\npublic class Celula\n{\n    public int Id { get; …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-core

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

ASP.NET Core 忽略属性或将其设置为在 ModelState 上有效

我在控制器上有这 2 个操作

\n\n
[HttpPost]\n    [ValidateAntiForgeryToken]\n    public IActionResult AddComDefeito(PecaRegisto pecaRegisto)\n    {\n        if (!ModelState.IsValid)\n        {\n            return PartialView("_AddComDefeitoPartial", pecaRegisto);\n        }\n\n        return PartialView("_AddComDefeitoPartial", new PecaRegisto());\n    }\n\n    [HttpPost]\n    [ValidateAntiForgeryToken]\n    public IActionResult AddSemDefeito(PecaRegisto pecaRegisto)\n    {\n        if (!ModelState.IsValid)\n        {\n            return PartialView("_AddSemDefeitoPartial", pecaRegisto);\n        }\n\n        return PartialView("_AddSemDefeitoPartial", new PecaRegisto());\n    }\n
Run Code Online (Sandbox Code Playgroud)\n\n

这是模型

\n\n
public class PecaRegisto\n{\n    public int Id { get; set; }\n\n    [Required]\n    [Range(1, int.MaxValue)]\n    public int Quantidade { get; set; }\n    [Required]\n    [Display(Name = "Refer\xc3\xaancia")]\n    public int ReferenciaId { get; set; }\n    public Referencia Referencia { …
Run Code Online (Sandbox Code Playgroud)

c# validation asp.net-core

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

HangFire 在 3 个给定时间重复执行作业

我已经设置了一个要在此时运行的重复作业,但我想在另外 2 个特定时间重复它。我该怎么做?

app.UseHangfireDashboard();

RecurringJob.AddOrUpdate<TerminaTurnos>(t => t.Termina(),  Cron.Daily(22, 10), TimeZoneInfo.Local);
Run Code Online (Sandbox Code Playgroud)

c# hangfire asp.net-core

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

在SQL Server中的case语句中使用set

我想使用一条CASE语句在SQL Server中设置一个变量。例如:

DECLARE @UNITY VARCHAR(5)
DECLARE @AUX VARCHAR(5)

CASE
    WHEN @UNITY = 'U1' THEN @AUX = 'M1'
    WHEN @UNITY = 'U2' THEN @AUX = 'M2'
    WHEN @UNITY = 'U3' THEN @AUX = 'M3'
END
Run Code Online (Sandbox Code Playgroud)

t-sql sql-server

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