Hari Gillala
Hari Gillala

Reputation: 11916

MVC-VIews-Display ASP.NET

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

Answers (2)

Carls Jr.
Carls Jr.

Reputation: 3078

@if(condition){
    <input type="button" value="the button"/>
}

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

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

Related Questions