Create Active/Current Menu Item In MVC3 / Razor

Add an HTML Helper:

 /// <summary>
        /// Helper to build a menu system with current/active context
        /// </summary>
        /// <param name="htmlHelper">The HTML helper.</param>
        /// <param name="linkText">The link text.</param>
        /// <param name="actionName">Name of the action.</param>
        /// <param name="controllerName">Name of the controller.</param>
        /// <returns></returns>
        public static MvcHtmlString MenuLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName)
            string currentAction = htmlHelper.ViewContext.RouteData.GetRequiredString("action");
            string currentController = htmlHelper.ViewContext.RouteData.GetRequiredString("controller");
            if (actionName == currentAction && controllerName == currentController)
                return htmlHelper.ActionLink(
                        @class = "current"
            return htmlHelper.ActionLink(linkText, actionName, controllerName);

Add this to your master page for the navigation elements

            <div id="nav">
                <ul id="menu">                 
                    <li>@Html.MenuLink("Search", "Search", "Colleague")</li>
                    <li>@Html.MenuLink("Favorites", "Index", "Favorites")</li>

CSS to style current/active nav item

#nav ul li a.current {

How Modernizr Works

Modernizr is pretty neat. If the browser supports a feature, it tags it with a css class at the base root level, basically appending to the html class attribute.

<html class=" js flexbox canvas canvastext webgl no-touch geolocation postmessage no-websqldatabase indexeddb hashchange history draganddrop no-websockets rgba hsla multiplebgs backgroundsize borderimage borderradius boxshadow textshadow opacity cssanimations csscolumns cssgradients no-cssreflections csstransforms csstransforms3d csstransitions fontface video audio localstorage sessionstorage webworkers applicationcache svg inlinesvg smil svgclippaths">

And then in your CSS you leverage that hierarchy

.cssgradients .searchResultItem 
background: #f4f4f4;
background: -moz-linear-gradient(top, #f4f4f4 0%, #e0e0e0 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f4f4f4), color-stop(100%,#e0e0e0));
background: -webkit-linear-gradient(top, #f4f4f4 0%,#e0e0e0 100%);
background: -o-linear-gradient(top, #f4f4f4 0%,#e0e0e0 100%);
background: -ms-linear-gradient(top, #f4f4f4 0%,#e0e0e0 100%);
background: linear-gradient(top, #f4f4f4 0%,#e0e0e0 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f4f4f4', endColorstr='#e0e0e0',GradientType=0 );
.borderradius .searchResultItem {	
	-webkit-border-radius: 4px;
	-moz-border-radius: 4px;
	border-radius: 4px;

If CSS Gradients aren’t supported by the browser it doesn’t get added to the root HTML CSS class and there for won’t get styled as the CSS hierarchy is broken.

How To Install SQL Server Management Studio 2008 R2 Express

1) Download Here (If link is dead search for “SQL Server 2008 R2 Management Studio Express”

2) Follow these instructions

Note: R2 install is a little different as you don’t have to select the SQL Server Express instance, but very similar. Also, Install Visual Studio 2010 first as it comes bundled with SQL Server 2008 Express.

If you need to debug SQL statements through say a SqlCommand or Entity framework you’ll want to install the full SQL Server Management Studio (Developer edition) and be sure to choose the “Complete” option under “Management Tools”