Reputation: 11916
I am using MVC for my Project. I have Page in a view and the page has some buttons in it. I want to hide some of the buttons depending on a boolean condition.
How Can I achieve that?
Upvotes: 0
Views: 68
Reputation: 1038710
You could use a view model containing a boolean property which should indicate whether a given section should be visible or not:
@if (Model.AreButtonsVisible)
{
<button>some button</button>
}
Another possibility is to write a custom HTML helper rendering those buttons which will take a boolean value indicating whether it should emit or not the corresponding HTML.
Upvotes: 2