Issue passing parameters through a C# class hierarchy in Blazor

I’m working on a project in Blazor and I have multiple C# base classes that inherit each other. My project is basically a digital application that the user progresses through, each page having them fill out a “page” of their application with additional information.

My classes include EnrollmentPage.cs, ApplicationPage.cs, and CalculatorBase.cs.

  • EnrollmentPage.cs is the overall base class that has all the services used on every page. Things like accessing the db, retrieving site settings, etc.
  • ApplicationPage.cs inherits EnrollmentPage.cs and fetches more specific data such as a users application and personal info for use on each page of the application.
  • CalculatorBase.cs inherits ApplicationPage.cs and contains methods for calculating the cost an applicant will pay based on their selections and info. CalculatorBase is only inherited by a few specific components for the purpose of calculating their cost.

One parameter of the ApplicationPage is Id as seen below:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public class ApplicationPage : EnrollmentPage
{
[Parameter]
public string Id { get; set; }
// rest of class...
}
</code>
<code>public class ApplicationPage : EnrollmentPage { [Parameter] public string Id { get; set; } // rest of class... } </code>
public class ApplicationPage : EnrollmentPage
{
    [Parameter]
    public string Id { get; set; }

    // rest of class...
}

The Id can be set to “Employee” or “Spouse” and is used to dynamically show different things on the page based on the user’s identity. The parameter is set within the page navigation of each razor component like so: @page "/company/{SettingId}/{Id}/RateCalculator". So, when the user navigates to the page “www.website.com/company/0/Employee/RateCalculator” DependentId gets set to “Employee”.

So my issue comes up within the components that inherit the CalculatorBase.cs class. These components are used on the RateCalculator page like this:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>@page "/company/{SettingId}/{DependentId}/RateCalculator"
@inherits Classes.CalculatorBase
<PageTitle>Rate Calculator</PageTitle>
<div>
<CalcComponent />
// rest of page...
</div>
</code>
<code>@page "/company/{SettingId}/{DependentId}/RateCalculator" @inherits Classes.CalculatorBase <PageTitle>Rate Calculator</PageTitle> <div> <CalcComponent /> // rest of page... </div> </code>
@page "/company/{SettingId}/{DependentId}/RateCalculator"
@inherits Classes.CalculatorBase

<PageTitle>Rate Calculator</PageTitle>

<div>
    <CalcComponent />

    // rest of page...
</div>

And this is the component:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>@* Calc Component *@
@inherits Classes.CalculatorBase
<div>
content
</div>
@code {
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
}
}
</code>
<code>@* Calc Component *@ @inherits Classes.CalculatorBase <div> content </div> @code { protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); } } </code>
@* Calc Component *@
@inherits Classes.CalculatorBase

<div>
    content
</div>

@code {
    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
    }
}

As you can see, ApplicationPage must be initialized in order for CalculatorBase to initialize and since CalculatorBase is inherited by both the page and the nested component, ApplicationPage is actually being initialized twice. My issue lies in the second initialization of the ApplicationPage occurring in the component.

The actual RateCalculator.razor page loads just fine and the CalculatorBase class initializes without issue indicating that the Id is not null which I have confirmed through debugging. However, the component never initializes. When CalculatorBase attempts to initialize and use the Id from ApplicationPage, it is null. I’m not sure why the component is not retrieving the Id correctly. For some reason this “second version” of ApplicationPage within the component is not getting the parameter.

I have other components that also require use of the CalculatorBase class on this page so explicitly defining the functionality within the component is not an option. Should I not inherit the CalculatorBase class within the component but instead create an instance of it? I’m not sure what else could possibly work to resolve this issue.

New contributor

Noah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật