Saurabh
Saurabh

Reputation: 1631

Set Navlink Href Property with Enum

In blazor application i am trying to set href property of NavLink with the help of Enum

Example :

 <NavLink class="nav-link" href="/Products/ProductType.All" Match="NavLinkMatch.All">
            <span class="oi oi-home" aria-hidden="true"></span> Home
 </NavLink>

Here ProductType is an Enum but in browser it make url like

ProductList/ProductTypes.All

instead of

ProductList/1

where 1 is for All

If i put @ symbol here

href="/ProductList/@ProductTypes.All"

than it say component attribute does not support complex content

what is the workaround here

Upvotes: 0

Views: 1161

Answers (1)

Phat Huynh
Phat Huynh

Reputation: 902

If your enum is

public enum ProductTypes{
   All = 1
}

so try to use this

href="@($"/ProductList/{(int)ProductTypes.All}")"

Hope it helps

Upvotes: 3

Related Questions