Reputation: 627
I have a partial view called like:
@Html.Partial("PersonSearch", new ViewDataDictionary { { "searchtypeselectvisible", false } })
In the razor file I have the html:
<div class="searchtypeselect" >
<input type="radio" name="searchtype" value="person" checked="checked" />Person
<input type="radio" name="searchtype" value="organisation" class="orgsearchradiobtn" />Organisation
</div>
I know I can access the data in the razor by using:
@ViewData["searchtypeselectvisible"]
Can someone explain how I can hide the div with class searchtypeselect if the value coming through is false and show it if the value is true?
Upvotes: 1
Views: 2544
Reputation: 15861
Conditional attribute rendering Conditional attribute rendering
If you have an attribute that might be null, in the past you've needed to do a null check to avoid writing out an empty attribute, like this:
<div @{if (myClass != null) { <text>class="@myClass"</text> } }>Content</div>
Now Razor is able to handle that automatically, so you can just write out the attribute. If it's null, the attribute isn't written:
<div class="@myClass">Content</div>
So if @myClass is null, the output is just this:
<div>Content</div>
try like this
@(ViewData["searchtypeselectvisible"]==true ? "yourDisplayClass" : "yourHidingDivClass");
Upvotes: 2
Reputation: 193
Use @{ if{ } }
to set attribute style with display: none
, easy.
Upvotes: 1