Hi @mehmood tekfirst ,
The Razor Class Library is a class library, Razor views, pages, controllers, page models, Razor components, View components, and data models can be built into a Razor class library (RCL), but the RCL should not use application settings or the configs like the appsetting.json file.
You can add the appsessting.json file in the Asp.net Core web/MVC application, then provide those settings to the components via the Component parameters.
For example, in the MVC application, add the appsetting.json file like this:
Then, when calling the component from the RCL, register the IConfiguration in the razor view/page, and transfer the data to the RCL component via the Component parameters:
the RCL component :
And then, the result like this:
You can view the source code from here: 208102-sourcecode.txt
Update:
Here is another method to transfer data from parent to child component:
Pages/ParameterParent.razor:
@page "/parameter-parent"
<h1>Child component (without attribute values)</h1>
<ParameterChild />
<h1>Child component (with attribute values)</h1>
<ParameterChild Title="Set by Parent"
Body="@(new PanelBody() { Text = "Set by parent.", Style = "italic" })" />
Shared/ParameterChild.razor:
<div class="card w-25" style="margin-bottom:15px">
<div class="card-header font-weight-bold">@Title</div>
<div class="card-body" style="font-style:@Body.Style">
@Body.Text
</div>
</div>
@code {
[Parameter]
public string Title { get; set; } = "Set By Child";
[Parameter]
public PanelBody Body { get; set; } =
new()
{
Text = "Set by child.",
Style = "normal"
};
}
PanelBody.cs:
public class PanelBody
{
public string? Text { get; set; }
public string? Style { get; set; }
}
Refer this article: Component parameters
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion