Pingpong
Pingpong

Reputation: 8019

How to show/hide an area within Razor View in ASP.NET MVC programmatically

I want to programmatically show/hide a group of fields (label, textfield, checkbox) on Razor view (.cshtml), based on a model value. The model is access to the view.

Thanks

Upvotes: 20

Views: 23278

Answers (1)

Neil N
Neil N

Reputation: 25278

In your Razor View cshtml:

@if(Model.RevealSecretPlans)
{
    <div>
      Giant frikkin laser
    </div>
}

This of course assumes RevealSecretPlans is a boolean

Upvotes: 57

Related Questions