<?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; extension</title>
	<atom:link href="http://www.ducdigital.com/tag/extension/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>
		<item>
		<title>Adding CDN Functionality to ASP.net MVC</title>
		<link>http://www.ducdigital.com/2009/11/24/adding-cdn-functionality-to-asp-net-mvc/</link>
		<comments>http://www.ducdigital.com/2009/11/24/adding-cdn-functionality-to-asp-net-mvc/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 11:52:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Asp.net MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[CDN]]></category>
		<category><![CDATA[content delivery network]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[htmlHelper]]></category>

		<guid isPermaLink="false">http://www.ducdigital.com/?p=125</guid>
		<description><![CDATA[I bet everyone develop webpage today are most likely to use a CDN for deliver images, video. Unlike in rails, MVC does not have a way to link with CDN, so i write this extension for your HtmlHelper so that you can easily link to a CDN that preconfig in your Web.config First, we need [...]]]></description>
			<content:encoded><![CDATA[<p>I bet everyone develop webpage today are most likely to use a CDN for deliver images, video. Unlike in rails, MVC does not have a way to link with CDN, so i write this extension for your HtmlHelper so that you can easily link to a CDN that preconfig in your Web.config</p>
<p>First, we need to add the ff. to web.config</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;appsettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;cdn&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;cdn.ducdigital.com, cn.ducdigital.com&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/appsettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>and then use the ff class:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</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;">class</span> CDNHelperExtension
<span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> CDNLink<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> HtmlHelper html, <span style="color: #FF0000;">string</span> path<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> CDN <span style="color: #008000;">=</span> ConfigurationSettings.<span style="color: #0000FF;">AppSettings</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;cdn&quot;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Replace</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot; &quot;</span>, <span style="color: #666666;">&quot;&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Split</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">','</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        Random r <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Random<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">return</span> CDNLink<span style="color: #000000;">&#40;</span>html, path, r.<span style="color: #0000FF;">Next</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span>, CDN.<span style="color: #0000FF;">Count</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> CDNLink<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> HtmlHelper html, <span style="color: #FF0000;">string</span> path, <span style="color: #FF0000;">int</span> ServerNumber<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> CDN <span style="color: #008000;">=</span> ConfigurationSettings.<span style="color: #0000FF;">AppSettings</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;cdn&quot;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Replace</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot; &quot;</span>, <span style="color: #666666;">&quot;&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Split</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">','</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>ServerNumber <span style="color: #008000;">&gt;=</span> CDN.<span style="color: #0000FF;">Count</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            ServerNumber <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">return</span> <span style="color: #666666;">&quot;http://&quot;</span> <span style="color: #008000;">+</span> CDN<span style="color: #000000;">&#91;</span>ServerNumber<span style="color: #000000;">&#93;</span> <span style="color: #008000;">+</span> path<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>in your View, just call:</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;">CDNLink</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;/images/&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">%&gt;</span></pre></div></div>

<p>Good luck!</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.ducdigital.com%2F2009%2F11%2F24%2Fadding-cdn-functionality-to-asp-net-mvc%2F&amp;linkname=Adding%20CDN%20Functionality%20to%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/2009/11/24/adding-cdn-functionality-to-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
