I have a model being populated by my data layer and then I have a partial view which is rendering an instance of that model.
<li class='<%= td.Active ? 'youarehere' : string.Empty %> <%= i == ViewData.Model.Count() - 1 ? 'last' : string.Empty %>'>
The problem is that class='' is invalid XHTML and I will need more complex logic to output the class attribute. What would be the proper way to go about this using ASP.NET MVC. Should the logic live in the view or the model?
I’m just starting out with MVC and I guess I’m still struggling on where exactly to draw the lines as far as where I put logic and what is an acceptable amount of logic for each layer to contain.
I’d probably implement the code to render that class attribute in a helper method. Either one specific to this view, or one slightly more generic. That way you have less code in your view and it could handle whether or not to even render the class attribute in the case there’s nothing to render.