asp.net mvc - conditional logic in mvc view vs htmlhelper vs action -


I have a big view that needs some conditional arguments to render how many HTML chunks in the middle of the scene Near my model is a property, which can have several different values ​​that define html for output.

I usually put conditional arguments in an HTML helper, but seeing that each output is the proper part of HTML, I'm not sure that saving them in the AC # file would be great. I can also put an argument in action and present different ideas but seeing that most of the scenes are same, it does not look good.

What is the best way to do this?

If I have left with many statements in my approach (or partial?), Which seems ugly (and obviously obsolete),

(I am using MVC3, if I can use some new and funky!)

I usually partially separate my own view of the part then my view calls partially with the conditional HTML. It keeps you main view from bloating.

In general, I try to avoid HTML. In which there is more than one element.

Something like this:

  @if (model.hasa) {@ Html.Partial ("widgetdetails-hasa")} @if (Model.HasB) {@ Html Assistant ("widgetdetails-hasb") // etc    

Comments