Disable div depending of variable razor with ASP.NET MVC4

3.7k Views Asked by At

I need disable a div depending of a variable razor. I tried a css class but not working because it is very simple disable with developer tools. there is a safe method to perform this task.? I use ASP.NET MVC 4.0

 .disableddiv {
pointer-events: none;
opacity: 0.4;

}

regards

2

There are 2 best solutions below

0
On

You could do something like

 @if (variable) { 
    <div>

    </div>
 }

Where variable is the variable that dictates if the div appears (like showDiv == true, for example) and div is the div you want to show.

0
On

Try this:

<div style="@(Model.booleanVariable ? "disabled=disabled" : "disabled=''")">Some links</div>