URL Parameters and/or data loading in layout files
Assume I have some pages as such:
- /websites/{WebsiteId:int}
- /websites/{WebsiteId:int}/faqs
- /websites/{WebsiteId:int}/testimonials
- /websites/{WebsiteId:int}/services
They all use the same layout for navigation, as such:
How do I get the
@WebsiteId
URL parameter "passed up" to the Layout or resolved from the URL? Is there anything built in to ASP.NET Core 8 for this?6 Replies
@schwartzmj might look at cascading parameters: https://stackoverflow.com/questions/66476652/is-there-any-way-to-communicate-to-main-layout-of-blazor-pages
Stack Overflow
Is there any way to communicate to main layout of blazor pages
Here I want to pass some title to the mainlayout.razor page so that my components or pages can update the title of header. Is there any possible way in blazor to do this ? Any help will be apprecia...
I used it recently to define title in page, setting the value in layout
I'd like to essentially do the opposite - read a value in the layout from the page (in this case a URL parameter)
same.. i set the title value "this is my page" in page
but the parameter is in layout
so depending on page, that title changes
ah ok. i read about cascading parameters a bit but it seemed like not a great solution having to perform the same logic in every single child of a layout when all i want is a path parameter 😦
im probably best off just not creating a layout file and instead a layout component that i just wrap every page with.
if i have to do the logic in a page anyway
since its dealing with url, you can also cascade as high up as the route parameters
i believe i did something like that to determine an "active" page on menu
and then depending on what it was from cascading route parameter, i set "active" in css class