20

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

Pingpong
  • 7,681
  • 21
  • 83
  • 209
  • do you want to conditionally render some html or you want to render it anyway and show hide using js on different browser events – Muhammad Adeel Zahid Jul 27 '11 at 16:42
  • Muhammad Adeel Zahid, conditionally render some html on server side. – Pingpong Jul 27 '11 at 16:45
  • possible duplicate of [How to hide a div element depending on Model value? MVC](http://stackoverflow.com/questions/22046108/how-to-hide-a-div-element-depending-on-model-value-mvc) – KyleMit Feb 01 '15 at 14:14

1 Answers1

56

In your Razor View cshtml:

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

This of course assumes RevealSecretPlans is a boolean

Neil N
  • 24,862
  • 16
  • 85
  • 145