Blazor Razor页面属性在单独的文件/类中

huangapple go评论78阅读模式
英文:

Blazor Razor page properties in separate file/class

问题

我有几个具有相同属性和分页列表方法的Razor组件。

这些属性位于Razor文件的@code部分。

如果这是一个常规的C#类,我会使用继承,但在这里是否也可以使用,如何操作?

@code {
  private bool myProperty { get; set; }

  public async Task ZoekenAsync(ChangeEventArgs args) {
    dosomething();
  }
}
英文:

I have several Razor components with the same properties and methods for the paging of the list.

These properties are in the @code part of the razor file.

If this was a regular C# class I would use inheritance, but is that here also possible and how would I do this?

@code {
  private bool myProperty { get; set; }

  public async Task ZoekenAsync(ChangeEventArgs args) {
    dosomething();
  }
}

答案1

得分: 2

A Razor component inherits after ComponentBase. Using @inherits directive makes it inherit after a different class. You can use the different class as a base with no problem as long as this class extends (inherits) ComponentBase. It is shown in the docs how to split your code: https://learn.microsoft.com/en-us/aspnet/core/blazor/components/?view=aspnetcore-7.0

英文:

A Razor component inherits after ComponentBase. Using @inherits directive makes it inherit after a different class. You can use the different class as a base with no problem as long as this class extends (inherits) ComponentBase. It is shown in the docs how to split your code: https://learn.microsoft.com/en-us/aspnet/core/blazor/components/?view=aspnetcore-7.0

huangapple
  • 本文由 发表于 2023年5月21日 03:30:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76297012.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定