简体   繁体   中英

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?

Have you tried using string interpolation for example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM