Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 873
Pingpong Avatar asked Jul 27 '11 16:07

Pingpong


People also ask

What is @model in Razor page?

It is a self-contained class that represents the data and behaviour of a specific "view" or page. The view model pattern is used extensively in MVC application development, where it mainly represents data, but typically little behaviour. In Razor Pages, the PageModel is also the view model.


1 Answers

In your Razor View cshtml:

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

This of course assumes RevealSecretPlans is a boolean

like image 135
Neil N Avatar answered Sep 17 '22 16:09

Neil N