【问题标题】:Insert new Blazor View or Component with JSRuntime (jQuery.append)使用 JSRuntime (jQuery.append) 插入新的 Blazor 视图或组件
【发布时间】:2020-10-16 01:38:10
【问题描述】:

这在理论上看起来很简单,但我找不到让它工作的方法:

在_Layout.cshtml中

window.insertComponent = function (selector, component) {
    $(selector).append(component);
}

在我的主要组件中:

private object Model {get;set;}
private string elementId {get;set;}
//...
private async void OnChange(EventArgs e)
{
    await JSRuntime.InvokeVoidAsync("insertComponent", new[] { "#" + elementId, new SomeChildComponentOrView() { Model = this.Model }});
}

如果有的话,我可以做些什么来完成这项工作?显然,new SomeChildComponentOrView() 不会编译。我从这里去哪里?

将 ASP.NET Core 3.1 与 Blazor 结合使用。

【问题讨论】:

    标签: c# jquery asp.net-core blazor


    【解决方案1】:

    我想你可能会检查你的 Setup.cs 文件,它应该被配置为添加服务并使用它。

    app.UseStaticFile()  
    

    因为如果你不使用它,它将在 JS 或 JQ 上不起作用。

    【讨论】:

      猜你喜欢
      • 2020-09-28
      • 1970-01-01
      • 2020-12-23
      • 2021-11-06
      • 2021-01-21
      • 2021-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多