<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DucDigital &#187; dry</title>
	<atom:link href="http://www.ducdigital.com/tag/dry/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ducdigital.com</link>
	<description>for ( $girl = 1; $girl &#60; $required; $girl++ ) { echo "I love DucDigital"; }</description>
	<lastBuildDate>Sat, 07 Aug 2010 09:12:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Automatic highlight menu for asp.net mvc.</title>
		<link>http://www.ducdigital.com/2010/01/12/automatic-highlight-menu-for-asp-net-mvc/</link>
		<comments>http://www.ducdigital.com/2010/01/12/automatic-highlight-menu-for-asp-net-mvc/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 07:53:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Asp.net MVC]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[automatic]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[dry]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[highlight]]></category>
		<category><![CDATA[htmlHelper]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[sidebar]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://www.ducdigital.com/?p=215</guid>
		<description><![CDATA[For a while now I've been wondering how to work out with the menu, so that it can automatic highlight with the least amount of code. So after a while, i come up with this. There are some part which I used the language helper I wrote in previous post. Just go ahead and replace [...]]]></description>
			<content:encoded><![CDATA[<p>For a while now I've been wondering how to work out with the menu, so that it can automatic highlight with the least amount of code. So after a while, i come up with this. There are some part which I used the language helper I <a href="http://www.ducdigital.com/2010/01/10/noob-guide-to-globalization-in-asp-net-mvc/">wrote in previous post</a>. Just go ahead and replace it to whatever that suit your needs.</p>
<p>This one i place on top of my Partial that contain the menu to get the action and controller, so that i can pass this to the extension.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #008000;">&lt;</span> <span style="color: #008000;">%</span>  <span style="color: #FF0000;">string</span> currentAction <span style="color: #008000;">=</span> ViewContext.<span style="color: #0000FF;">RouteData</span>.<span style="color: #0000FF;">Values</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;action&quot;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #FF0000;">string</span> currentController <span style="color: #008000;">=</span> ViewContext.<span style="color: #0000FF;">RouteData</span>.<span style="color: #0000FF;">Values</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;controller&quot;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">%&gt;</span></pre></div></div>

<p>This is the sidebar Item, basically this will generate a "li" tag with a link and your custom class to indicate whether the link is currently used in the page / highlight. There is a if check in this method, it check for both current action and method if it actually fit the link.<br />
so if you are doing a higher level menu item, in this case, a controller menu, you can just simply compare the controller instead of both.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> SidebarItem<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Web</span></span>.<span style="color: #0000FF;">Mvc</span>.<span style="color: #0000FF;">HtmlHelper</span> html, <span style="color: #FF0000;">string</span> currentAction, <span style="color: #FF0000;">string</span> currentController, <span style="color: #FF0000;">string</span> action, <span style="color: #FF0000;">string</span> controller, <span style="color: #FF0000;">string</span> languageKey, <span style="color: #0600FF;">params</span> <span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        TagBuilder tb <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> TagBuilder<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;li&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Equals</span><span style="color: #000000;">&#40;</span>currentAction, action, StringComparison.<span style="color: #0000FF;">OrdinalIgnoreCase</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Equals</span><span style="color: #000000;">&#40;</span>currentController, controller, StringComparison.<span style="color: #0000FF;">OrdinalIgnoreCase</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            tb.<span style="color: #0000FF;">GenerateId</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;activemenu&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #FF0000;">string</span> text <span style="color: #008000;">=</span> html.<span style="color: #0000FF;">Language</span><span style="color: #000000;">&#40;</span>languageKey, args<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #FF0000;">string</span> link <span style="color: #008000;">=</span> html.<span style="color: #0000FF;">ActionLink</span><span style="color: #000000;">&#40;</span>text, action, controller<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToHtmlString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        tb.<span style="color: #0000FF;">SetInnerText</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;{0}&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">return</span> <span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span>tb.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #666666;">&quot;&lt;span&gt;&quot;</span><span style="color: #008000;">+</span>link<span style="color: #008000;">+</span><span style="color: #666666;">&quot;&lt;/span&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>And here is the actual sample usage of the code above:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #008000;">&lt;</span> <span style="color: #008000;">%=</span> Html.<span style="color: #0000FF;">SidebarItem</span><span style="color: #000000;">&#40;</span>currentAction, currentController, <span style="color: #666666;">&quot;index&quot;</span>, <span style="color: #666666;">&quot;home&quot;</span>, <span style="color: #666666;">&quot;index&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">%&gt;</span></pre></div></div>

<p>This help a lot when you create a menu that can automatic indicate whether you are in that page or not.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.ducdigital.com%2F2010%2F01%2F12%2Fautomatic-highlight-menu-for-asp-net-mvc%2F&amp;linkname=Automatic%20highlight%20menu%20for%20asp.net%20mvc."><img src="http://www.ducdigital.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.ducdigital.com/2010/01/12/automatic-highlight-menu-for-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
