简体   繁体   English

在 blazor 的共享组件中设置 class 属性

[英]Setting a class property in a shared component in blazor

I have a navbar which is a shared component in Blazor ServerSide.我有一个导航栏,它是 Blazor ServerSide 中的共享组件。 I want to set the address in the href to that I can pass the users ID.我想将 href 中的地址设置为可以传递用户 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).还有其他几个变体,但我收到一条错误消息,指出组件属性不支持复杂内容(混合 C# 和标记)。 Is there anyway the @StudentId can be put in here?无论如何,@StudentId 可以放在这里吗?

Have you tried using string interpolation for example:您是否尝试过使用字符串插值,例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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