Cleaner way of conditionally rendering part of a view in asp.net mvc2 -


I have an inline style that I want to apply through a ViewDataDictionary to a partial view based on a parameter.

My esque looks like this -

   Style = "display: none;" & Lt;%}% & gt; & Gt; ... & lt; / Div & gt;  

Is there a cleaner way to do this?

Edit:
Just to make it clear, this is a partial view already using a vigorous type model, so, in partial view, There was a way to provide information, which I could not see in the model because it was actually being called for every entry in the collection container in the model for my included scene.

You can put it within the conditional operator:

  Lt; Div & lt;% =! (BULL) View Data ["View"]? "Style = 'display: none;'": ""%> & gt; & Gt; ... & lt; / Div & gt;  

I have not found an MVC project open for testing, but the following tasks in standard ASP.Net. The following will be shown:

  & lt; Div id = "foo" & lt;% = "a" == "b"? "Style = 'display: none;'": ""%> / & Gt;  

and its style will be set correctly:

  & lt; Div id = "foo" & lt;% = "a" == "one"? "Style = 'display: none;'": ""%> / & Gt;  

Comments