I know that there shouldn't be code in the views, but in the project I'm working on, I have a lot of logic in the views.
My homepage has
<% Html.RenderPartial("SearchResults"); %>
Now in a partial view, I have quite a bit of logic, for example:
<div id="RestaurantsList"> <%if (Model.restaurantsList.Count() > 0) { foreach (var item in Model.restaurantsList) { %> <% Html.RenderPartial("SearchResult", item); %> <% } %> <% } else { Html.RenderPartial("NoResults"); } %>
Now I can make the home controller return another view based on the empty blank, but I really don't want this, because there are several things in the Index view that I want to display, regardless of whether there are any results or not.
The only thing I can think of here is encapsualte this in a helper method like Html.SearchResults. But then I need an assistant to call renderPartial for each search result. This is not like a clean separation of concerns.
I would still have to have an if if statement in a partial view.
How would you do better?
asp.net-mvc refactoring partial-views
ddd
source share