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

2020-04-02 05:58发布

问题:

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

回答1:

In your Razor View cshtml:

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

This of course assumes RevealSecretPlans is a boolean