Personally, I don't like the logic in the view. As a rule, I usually put the logic in the model and pass it into the view and believe that the view should show how the data should look, and not manipulate the data.
As an alternative approach, you can have a Navigation Model and pass:
ViewData["ActiveMenu"]
to your controller and fill in the Navigation Model .
public class NavigationModel { public string UserFocus { get; private set; } public string CardFocus { get; private set; } public string CarrierFocus { get; private set; } public NavigationModel(string ActiveMenu) {
Your opinion will look like this:
@Model NavigationModel <ul class="nav nav-tabs"> <li class="@Model.UserFocus">User view link</li> <li class="@Model.CardFocus">card view link</li> <li class="@Model.CarrierFocus">Carrier view link</li> </ul>
Which, in my opinion, is cleaner.
source share