To implement it, we amend the _host.cshtml to add a component that renders it in the section as per your question: Html.RenderComponentAsync(RenderMode.Server)) We need to register this as a scoped service in Startup.cs: // declare the HeadState for DI The title property is read-only so it has to be set via SetTitle, which triggers the HeadChanged event so consumers know it's amended. The HeadState class is a state container to allow us to set the page title. Here is a quick sample that just sets the page title, but you can extend it to cover for example. Writing in the form of State container will also help in usage. This means you can control the scope of the data (global? session?) as well as make it available on any page/component you need. I would suggest the best way to make some information available across a Blazor application is to use the service system and Dependency Injection. This StoreData variable must be available in dynamic meta data, because I have to choose different CSS files for other stores.īecause it is web service call and costs time. StoreData = await AppState.GetStoreData(My.StoreId) Using var tl = new TimeLogger($"MainLayout.razor OnInitializedAsync()") Protected override async Task OnInitializedAsync() I'm getting data in MainLayout.razor: StoreCompleteDTO StoreData I want to know the used url and give some data dynamically.īut with my knowledge right now I just can do it twice in each component (DocumentMetadataComponent + App). Problem now is that I have to set some variables on that top Level to overgive and interpret once. Works great so far (can make title, description, etc. _Hosts.cshtml (see the code snippet in element): Html.RenderComponentAsync(RenderMode.ServerPrerendered)) ![]() Just used the great free Blazor code of DevExpress to implement custom data on runtime:
0 Comments
Leave a Reply. |