Search code examples
c#blazorblazor-server-sideblazor-client-side

Setting a class property in a shared component in blazor


I have a navbar which is a shared component in Blazor ServerSide. I want to set the address in the href to that I can pass the users ID. I have tried this:

<NavLink class="nav-link" href="/student/registerguest/@StudentId">
                <span class="oi oi-plus" aria-hidden="true"></span> Register Guest
            </NavLink>

And several other variations but I am getting an error that says Component attributes do not support complex content (mixed C# and markup). Is there anyway the @StudentId can be put in here?


Solution

  • Have you tried using string interpolation for example:

    href=@($"/student/registerguest/{student.StudentId}")