I have an inline style I want to apply to a partial view based on a parameter passed in to it via the ViewDataDictionary.
My ascx look like this –
<div <% if ((bool)ViewData["Visible"] == false) { %> style="display:none;" <% } %>>
...
</div>
Is there a cleaner way to do this?
Edit:
Just to clarify, this is a partial view which is already using strongly typed model. So, I needed a way of passing extra information to the partial view which I couldn’t have in the model because it was actually being called for each entry of a collection container in the model for my containing view.
You could contain it within a conditional operator:
I’ve not got an MVC project open to test, but the following work in standard ASP.Net. The following will be shown:
And this will have the style correctly set: