Lord Vermillion
Lord Vermillion

Reputation: 5424

Razor if-statement using c# method

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?

Upvotes: 0

Views: 669

Answers (2)

Georgi Karadzhov
Georgi Karadzhov

Reputation: 771

@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

Upvotes: 1

Backs
Backs

Reputation: 24903

@if (Project.HelpMethods.IsOk())
{
    <li id="menuOptionAppleIds">
        @Html.ActionLink("A", "A", "Home")
    </li>
}

Upvotes: 4

Related Questions