<?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>Codelab Blog &#187; MVC</title>
	<atom:link href="http://blog.codelab.co.nz/tag/mvc/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.codelab.co.nz</link>
	<description>Technical Articles and News from Codelab Ltd</description>
	<lastBuildDate>Tue, 17 Jan 2012 13:10:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>When to use TempData in ASP.NET MVC</title>
		<link>http://blog.codelab.co.nz/2011/12/05/when-to-use-tempdata-in-asp-net-mvc/</link>
		<comments>http://blog.codelab.co.nz/2011/12/05/when-to-use-tempdata-in-asp-net-mvc/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 02:27:37 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=366</guid>
		<description><![CDATA[The problem I came across this problem where I had a basic list of items and for each if these items I wanted to add a delete action on my controller. I wanted to add some error checking around the delete action so if someone attempted to modify the URL and enter a incorrect parameter [...]]]></description>
			<content:encoded><![CDATA[<p><strong>The problem</strong></p>
<p>I came across this problem where I had a basic list of items and for each if these items I wanted to add a delete action on my controller. I wanted to add some error checking around the delete action so if someone attempted to modify the URL and enter a incorrect parameter into my controller, I wanted to redirect back to the previous controller and notify the user of this mistake. Take this example. I have a Product Controller and the Index Action and View lists all of the products. I have a delete action on the Product Controller which checks if the productId parameter is valid and then removes the product and redirects to the Index action using the RedirectToAction method.</p>
<p><strong>The solution</strong></p>
<p>When validating the productId, if its NOT valid simply add a new key/value to the TempData object and call the RedirectToAction method. TempData stores data for short periods of time for the current and next HTTP request. In your index view, you can check to see if your key/value pair exists and display a error message. If you refresh the page, you will notice the data from the TempData will be gone. Remember to use RedirectToAction where possible as this is more friendly with Unit Testing rather than using the HttpResponse redirect method.</p>
<p>This reference illustrates a good understanding between TempData, ViewBag and ViewData.</p>
<p><a title="Difference between ViewBag, ViewData and TempData" href="http://rachelappel.com/when-to-use-viewbag-viewdata-or-tempdata-in-asp.net-mvc-3-applications" target="_blank">http://rachelappel.com/when-to-use-viewbag-viewdata-or-tempdata-in-asp.net-mvc-3-applications</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2011/12/05/when-to-use-tempdata-in-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Areas and ASP.NET MVC Routes Tip</title>
		<link>http://blog.codelab.co.nz/2011/08/28/areas-and-asp-net-mvc-routes-tip/</link>
		<comments>http://blog.codelab.co.nz/2011/08/28/areas-and-asp-net-mvc-routes-tip/#comments</comments>
		<pubDate>Sun, 28 Aug 2011 10:21:10 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Coding Practices]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=354</guid>
		<description><![CDATA[Lets say that you have several areas define in your ASP.NET MVC solution. You find that when you run your application you get the following error &#8220;Multiple types were found that match the controller named ‘Home’.&#8221;. This is because ASP.NET MVC finds all the routing definitions (i.e in each area.cs file or the global.asax) and [...]]]></description>
			<content:encoded><![CDATA[<p>Lets say that you have several areas define in your ASP.NET MVC solution. You find that when you run your application you get the following error <strong><em>&#8220;Multiple types were found that match the controller named ‘Home’.&#8221;</em></strong>. This is because ASP.NET MVC finds all the routing definitions (i.e in each area.cs file or the global.asax) and sees conflicts with duplicate controller names.<br />
Simple solution is to associate the namespace with the routes you are registering. Take the example below:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">// global.asax route<br />
routes.MapRoute(<br />
&quot;Default&quot;, // Route name<br />
&quot;{controller}/{action}/{id}&quot;, // URL with parameters<br />
new { controller = &quot;Home&quot;, action = &quot;Index&quot;, id = UrlParameter.Optional }, // Parameter defaults<br />
new string[] { &quot;MyApplication.Controllers&quot; } // Controller Namespace<br />
);<br />
?<br />
// Area Registration Route<br />
context.MapRoute(<br />
MyArea_default,<br />
&quot;MyArea/{controller}/{action}/{id}&quot;,<br />
new { action = &quot;Index&quot;, id = UrlParameter.Optional },<br />
new string[] { &quot;MyApplication.Areas.MyArea.Controllers&quot; }<br />
);</div></div>
<p>Credit to <a href="http://steve.testasoftware.com/?p=40">Steve Testa</a>, Thanks!.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2011/08/28/areas-and-asp-net-mvc-routes-tip/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Compiler Error Message: CS1973</title>
		<link>http://blog.codelab.co.nz/2011/02/06/compiler-error-message-cs1973/</link>
		<comments>http://blog.codelab.co.nz/2011/02/06/compiler-error-message-cs1973/#comments</comments>
		<pubDate>Sun, 06 Feb 2011 10:42:44 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=309</guid>
		<description><![CDATA[I came across this error when I was trying to use the @Render method to render a view while passing through a object that will act as the model for that view. Compiler Error Message: CS1973: &#8216;System.Web.Mvc.HtmlHelper&#8217; has no applicable method named &#8216;Render&#8217; but appears to have an extension method by that name. Extension methods [...]]]></description>
			<content:encoded><![CDATA[<p>I came across this error when I was trying to use the @Render method to render a view while passing through a object that will act as the model for that view.</p>
<p>Compiler Error Message: CS1973: &#8216;System.Web.Mvc.HtmlHelper&#8217; has no  applicable method named &#8216;Render&#8217; but appears to have an extension  method by that name. Extension methods cannot be dynamically  dispatched. Consider casting the dynamic arguments or calling the  extension method without the extension method syntax.</p>
<p>The issue was that the compiler could not choose the correct method because my model was &#8220;dynamic&#8221;.</p>
<p>The correct syntax is:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">@Html.Partial(&quot;_MyList&quot;,(MyClass)myObject)</div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2011/02/06/compiler-error-message-cs1973/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using ASP.NET MVC on IIS6 or below</title>
		<link>http://blog.codelab.co.nz/2009/01/13/using-aspnet-mvc-on-iis6-or-below/</link>
		<comments>http://blog.codelab.co.nz/2009/01/13/using-aspnet-mvc-on-iis6-or-below/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 09:19:48 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=53</guid>
		<description><![CDATA[When you are building a web applicatio using the ASP.NET MVC framework on IIS7, it URL routing works smoothly and without any dramas.   But when it comes to IIS6 you have to make a comprimse especially if you are developing web apps within a shared hosting envoirnment.   I found the easist way is to change [...]]]></description>
			<content:encoded><![CDATA[<p>When you are building a web applicatio using the ASP.NET MVC framework on IIS7, it URL routing works smoothly and without any dramas.   But when it comes to IIS6 you have to make a comprimse especially if you are developing web apps within a shared hosting envoirnment.   I found the easist way is to change the URL routing table within the Global.asax file.</p>
<p>Origional file:</p>
<blockquote>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">public class GlobalApplication : System.Web.HttpApplication</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;{</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;public static void RegisterRoutes(RouteCollection routes)           {                routes.IgnoreRoute(&quot;{resource}.axd/{*pathInfo}&quot;);                routes.MapRoute(                     &quot;Default&quot;,// Route name                     &quot;{controller}/{action}/{id}&quot;,// URL with parameters                     new { controller = &quot;Home&quot;, action = &quot;Index&quot;, id = &quot;&quot; } &nbsp;                         // Parameter defaults                );</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;}</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;protected void Application_Start()</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;{</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;RegisterRoutes(RouteTable.Routes);</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;}</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;}</div></div>
</blockquote>
<p>Change to the following:</p>
<blockquote>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">public class GlobalApplication : System.Web.HttpApplication</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;{</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;public static void RegisterRoutes(RouteCollection routes)           {                routes.IgnoreRoute(&quot;{resource}.axd/{*pathInfo}&quot;);                routes.MapRoute(                     &quot;Default&quot;,// Route name                     &quot;{controller}.aspx/{action}/{id}&quot;,// URL with parameters                     new { controller = &quot;Home&quot;, action = &quot;Index&quot;, id = &quot;&quot; } &nbsp;                         // Parameter defaults                );</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;}</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;protected void Application_Start()</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;{</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;RegisterRoutes(RouteTable.Routes);</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;}</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;}</div></div>
</blockquote>
<p>Just add the .aspx extension so that it registers through the .NET Framework.</p>
<p>ALSO remember to do a Response.Redirect in the default.aspx page so that the first page will be your default URL routing page, otherwise you will receive a HttpException &#8220;The incoming request does not match any route.&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2009/01/13/using-aspnet-mvc-on-iis6-or-below/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

