I have a C# MVC project using Razor for views.
In my _Layout.cshtml file i want to hide menuoptions based on bools in a helper class.
@using Project.HelpMethods;
<li id="menuOptionAppleIds">
@Html.ActionLink("A", "A", "Home")
</li>
How do i call a statis bool method in HelpMethods and use in as the expression in an if statement around the <li>
element?
@if (Project.HelpMethods.IsOk())
{
<li id="menuOptionAppleIds">
@Html.ActionLink("A", "A", "Home")
</li>
}
@if(Helper.ShowMenuOption(x))
{
<li id="menuOptionAppleIds">
@Html.ActionLink("A", "A", "Home")
</li>
}
You can use if-statements and method calls in razor as in every other C# file. The difference is to ad @symbol before the c# code
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.