Branching logic in an MVC view

Posted by Alex Kilpatrick on Stack Overflow See other posts from Stack Overflow or by Alex Kilpatrick
Published on 2010-05-26T01:29:21Z Indexed on 2010/05/26 1:31 UTC
Read the original article Hit count: 253

Filed under:
|

I find myself writing a lot of code in my views that looks like the code below. In this case, I want to add some explanatory HTML for a novice, and different HTML for an expert user.

<% if (ViewData["novice"] != null ) { %> some extra HTML for a novice <% } else { %> some HTML for an expert <% } %>

This is presentation logic, so it makes sense that it is in a view vs the controller. However, it gets ugly really fast, especially when ReSharper wants to move all the braces around to make it even uglier (is there a way to turn that off for views?).

My question is whether this is proper, or should I branch in the controller to two separate views? If I do two views, I will have a lot of duplicated HTML to maintain.

Or should I do two separate views with a shared partial view of the stuff that is in common?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about views