英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论