<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Chris van de Steeg</title>
	
	<link>http://www.chrisvandesteeg.nl</link>
	<description>What's practical is logical</description>
	<lastBuildDate>Fri, 28 Sep 2012 07:36:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/chrisvandesteeg" /><feedburner:info uri="chrisvandesteeg" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by-sa/2.0/</creativeCommons:license><item>
		<title>MVC MusicStore for Sitecore 6.6</title>
		<link>http://feedproxy.google.com/~r/chrisvandesteeg/~3/D57xdC05HJE/</link>
		<comments>http://www.chrisvandesteeg.nl/2012/07/19/mvc-musicstore-for-sitecore-6-6/#comments</comments>
		<pubDate>Thu, 19 Jul 2012 12:13:14 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[sitecore]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/?p=397</guid>
		<description><![CDATA[THIS IS AN UPDATED VERSION OF Sitecore MVC Music Store TO MAKE IT WORK WITH THE OFFICIAL SUPPORTED MVC INSIDE SITECORE 6.6 In my last blog post about using the MVC Framework inside Sitecore, I announced that I’d write another blog post on how to actually create a real world application with MVC inside Sitecore. [...]]]></description>
				<content:encoded><![CDATA[<p><strong>THIS IS AN UPDATED VERSION OF <a href="http://www.chrisvandesteeg.nl/2012/05/17/sitecore-mvc-music-store/">Sitecore MVC Music Store</a> TO MAKE IT WORK WITH THE OFFICIAL SUPPORTED MVC INSIDE SITECORE 6.6</strong></p>
<p>In my last blog post about using the MVC Framework inside Sitecore, I announced that I’d write another blog post on how to actually create a real world application with MVC inside Sitecore. The first blog post was just a proof of concept, creating a real world application with it, helps completing the code.</p>
<p>Sitecore <a href="http://www.sitecore.net/Community/Business-Blogs/Technical-Trends/Posts/2012/06/MVC-and-Sitecore-651-Overview.aspx" target="_blank">has announced</a> that it will support MVC in Sitecore version 6.6. Great news! This tutorial will use the technical preview of Sitecore 6.6 to rebuild the mvc musicstore inside a Sitecore environment.</p>
<p>Since Microsoft has already created a nice tutorial for getting started with ASP.NET MVC : <a href="http://www.asp.net/mvc/tutorials/mvc-music-store" target="_blank">MVC Music Store tutorial</a>. I figured it’d also be a nice tutorial to get started with MVC inside Sitecore. It’s an easy to follow, small tutorial, which makes it easy to go through for both experts and beginners in the world of MVC. Experts can just skip the parts explaining how MVC itself works and go straight to the action. For beginners, the entire tutorial takes less then 2 hours. It will be the best invested 2 hours of your programmer’s life so far <img src='http://www.chrisvandesteeg.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ! </p>
<p>Once you have completed the Microsoft tutorial, the steps in this blog-post will help you transform it to a Sitecore project.</p>
<h4>Step 1 – complete the tutorial</h4>
<p>First, follow the entire tutorial (or if you’re an expert on MVC already, just download the package:<a href="http://mvcmusicstore.codeplex.com/">http://mvcmusicstore.codeplex.com/</a>)</p>
<h4>Step 2 – Get Sitecore running with MVC support</h4>
<p>Follow the <a href="http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2012/06/Sitecore-MVC-Playground-Part-1-Enable-MVC.aspx">instructions given by John West</a> to get Sitecore 6.6 with MVC support up and running.</p>
<h4>Step 3 – copy contents</h4>
<p>Copy the wwwroot contents of the mvcmusicstore project into the wwwroot of an existing Sitecore project (or create a new one first), but <strong>SKIP the web.config </strong>files! Note that you should copy the web-files to the web folder of your sitecore project! (if you downloaded the package, the web-content is inside the ‘MvcMusicStore’ folder inside the zip file)</p>
<p>Now open the Sitecore project in visual studio, and add the project you just copied to your solution (File –&gt; Add –&gt; Existing project).</p>
<h4>Step 4 – connectionstrings</h4>
<p>Copy the connectionstring in the web.config of the original created MVCMusicStore project, to the App_Config\Connectionstrings.config inside your sitecore solution.</p>
<h4>Step 5 – Global.asax</h4>
<p>Modify the default route in global.asax.cs. You can do that by adding any static string value in front of the default route. I chose ‘musicstore_api’. Doing this will make all your controller actions accessible through /musicstore_api/home/index, this could come in handy for stuff you need to access without going through sitecore (eg. ajax calls, delete actions, etc)</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image.png" width="544" height="212"/></p>
<p>If you now run your application, and everything went fine, your application should show the default sample Sitecore homepage. If you now go to /musicstore_api/ , the musicstore should work exactly the same as when you finished the original tutorial. (Note: if you downloaded the sample code instead of making your own, and you run in to the error code <em>“Unable to find the requested .Net Framework Data Provider. It may not be installed.”</em>, you need to install <a href="http://www.microsoft.com/en-us/download/details.aspx?id=17876" target="_blank">MS Sql Compact CE 4.0</a>)</p>
<p>These first 5 steps were the steps required to get an existing MVC application working inside the sitecore wwwroot. Now we’ll start modifying the existing app to become an application fully powered by sitecore!</p>
<h4>Step 6 – Create layout</h4>
<p>In Visual Studio, copy /Views/Shared/_Layout.cshtml to /Views/Shared/_SitecoreLayout.cshtml<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image2.png" width="254" height="180"/></p>
<p>Open _SitecoreLayout.cshtml and replace <br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image3.png" width="167" height="64"/><br />with<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image4.png" width="372" height="69"/></p>
<p>In the Sitecore Content Editor user interface, navigate to the /sitecore/layout/Layouts/ folder that contains the default layouts. Underneath, create a new ‘Layout folder’ named ‘MVC MusicStore’. Now copy the ‘Sample layout’ item and paste it inside your newly created folder (using your right mouse button), name it ‘Shared layout’<br /><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image21.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image[2]" border="0" alt="image[2]" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image2_thumb.png" width="193" height="159"/></a></p>
<p>Having your newly pasted layout selected, go to the ‘content’ tab, and change the Path field to /views/shared/_SitecoreLayout.cshtml<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image5.png" width="295" height="178"/></p>
<h4>Step 7 – Create Sitecore templates</h4>
<p>Run your application, and go the the Sitecore desktop (/sitecore/shell/default.aspx) and open the template manager.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Screenshot - 3-6-2012 , 14_14_50" border="0" alt="Screenshot - 3-6-2012 , 14_14_50" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/Screenshot-3-6-2012-14_14_50.png" width="443" height="227"/> </p>
<p>Add a new template folder underneath ‘Templates\User defined’ called ‘MVC MusicStore. Underneath that new folder, add a new template.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image3.png" width="421" height="348"/></p>
<p>Call the new template ‘Default page’ and just let the base template field as it is. Click next, next, finish.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image4.png" width="460" height="232"/></p>
<p>Select your new ‘Default page’ item in the tree, and on the ribbon ‘Builder options’ click the ‘Standard values’ button in the template section.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image5.png" width="123" height="64"/></p>
<p>And next on the ‘Presentation’ ribbon, click the ‘Details’ button in the layout section</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image6.png" width="94" height="64"/></p>
<p>This will open the layout details wizard:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image7.png" width="530" height="380"/></p>
<p>Here, click the Edit-button under the ‘Default’ section (marked with a red border in the screenshot above), which will open the “Device Editor” popup:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image8.png" width="391" height="182"/></p>
<p>In the dropdown, choose the ‘Shared Layout’ the MVC MusicStore folder and click OK twice</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image6.png" width="154" height="156"/></p>
<h4>Step 9 – Register controller actions</h4>
<p>Unfortunately, Sitecore does not automatically detect all controller actions and registers them as a rendering, like BoC.Sitecore.Mvc does. I will update BoC.Sitecore.Mvc ofcourse, to auto register all your controller actions, but for now, you will have to add them by hand.</p>
<p>In the Sitecore contenteditor, navigate to /sitecore/Layout/Renderings. Click the item with your right mouse button and choose Insert-&gt;Rendering Folder, name it ‘MVC MusicStore’. Inside that folder, add another folder ‘Home’. Click with the right mouse button on that Home item, and choose Insert-&gt;Controller rendering. Name it ‘Index’<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image7.png" width="389" height="435"/><br />Select your new rendering, and in the content tab, enter ‘Home’ as the controller, and ‘Index’ as the action.<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image8.png" width="481" height="162"/></p>
<p>Now you’ll have to do this for all actions wer’re going to use in this tutorial, your tree should end up like this:<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image9.png" width="235" height="265"/></p>
<h4>Step 9 – Create sitecore items</h4>
<p>Based on our previously created ‘Default page’ template, we’re now going to add the Sitecore items based on this template.</p>
<p>Open up the content editor in sitecore, and delete the exiting homepage item (/sitecore/content/home). Add a new Home item by click the ‘Content’ item with the right mouse button and choosing ‘Insert –&gt; Insert from Template’.<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image10.png" width="353" height="202"/></p>
<p>Call the item Home and pick our just created ‘Default page’ template as it’s template<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image11.png" width="347" height="318"/></p>
<p>Using this same template, create the following tree inside Sitecore:<br /><img alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image12.png"/><br /><strong>IMPORTANT </strong>Notice the * in front of Genre and Id…. these are wildcard mappings! The <strong>name</strong>of the items should be * and the <strong>displayname</strong> *Genre and *Id.</p>
<h4>Step 10 – Attach controller actions</h4>
<p>On these pages, we’ll attach the appropiate MVC Action. Start with the Home item. Click on it in the tree, and open the ‘Presentation’ ribbon. Now click on the details button:<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image13.png" width="94" height="64"/><br />This will open the layout popup<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image10.png" width="504" height="398"/></p>
<p>Now click the Edit-button under the ‘Default’ section (marked with a red border in the screenshot above), which will open the “Device Editor” popup<br /> <img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image11.png" width="500" height="162"/></p>
<p>Click the controls tab, and choose ‘Add’. That will bring up the ‘Select a rendering’ window.<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image12.png" width="503" height="359"/></p>
<p>Choose Renderings/MVC MusicStore/Home/Index and enter ‘main’ as the placeholder name (remember we added that $Html.SitecorePlaceholder(“main”) to _SitecoreLayout.cshtml?). Click on Select, and then on OK twice to save all your changes.</p>
<p>Now do the same for all other pages you’ve created except the ‘checkout’ page (that is just a placeholder). The other pages should get the following controls:</p>
<ul>
<li>Checkout –&gt; Renderings/MVC MusicStore/Checkout/Complete  </li>
<li>Checkout/AddressAndPayment –&gt; Renderings/MVC MusicStore/Checkout/AddressAndPayment  </li>
<li>ShoppingCart –&gt; Renderings/MVC MusicStore/ShoppingCart/Index  </li>
<li>Store –&gt; Renderings/MVC MusicStore/Store/Index  </li>
<li>Store/Browse –&gt; Renderings/MVC MusicStore/Store/Browse  </li>
<li>Store/Browse/*Genre –&gt; Renderings/MVC MusicStore/Store/Browse  </li>
<li>Store/Details –&gt; Renderings/MVC MusicStore/Store/Details  </li>
<li>Store/Details/*Id –&gt; Renderings/MVC MusicStore/Store/Details </li>
</ul>
<h4>Step 11 – Publish &amp; test</h4>
<p>Now, publish your entire site (! beware that if you’re using the sample database with the sample item template, that there is a worfklow attached to the new items by default… you need to approve them before publishing). After publishing, you can go checkout the homepage of your website. HEY! It’s just showing ‘default page’ ??</p>
<p>This is because by default, Sitecore holds a default.aspx in the root, and MVC by default does not trigger any route if the file exists on disk. You can enable routing for existing files by adding ‘routes.RouteExistingFiles = true;’ to the RegisterRoutes method in global.asax.cs, or you can just delete the default.aspx. I chose the latter one: just rename your default.aspx page in the root of your website’s folder to default.aspx.bak. Refresh your homepage.</p>
<p>Much better, but now what! the navigation menu and logo are shown twice!</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image17.png" width="822" height="547"/></p>
<h4>Step 12 – Modify viewstart</h4>
<p>The reason for the page being displayed twice, is because the default MVC Musicstore project does not take into account that the views can be accessed as a child-action. Adding the actions as a sublayout inside our sitecore pages, makes the actions being rendered as childactions. To skip the layout being rendered in child mode, open Views/_ViewStart.cshtml and modify the one line that’s in there to:<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image13.png" width="765" height="123"/></p>
<p>(I do hope Sitecore will support ViewContext.IsChildAction, as that is the official way to check if your view should be partially rendered)</p>
<p>Save the file, and check the homepage again: Looking just fine now!</p>
<h4>Step 13 – Modify Links</h4>
<p>Though the website looks good now, all links are pointing to the /musicstore_api folder. Even though that will work just fine, that’s the native MVC you’re calling then. To point all links to the sitecore versions, we’ll have to change all link renderings. This is the most dramatic change in an existing MVC application. In fact, we’ll break compatibility here, since the links will become Sitecore specific. I haven’t figured out a way to keep this compatible. Then again, I don’t think you’d ever even want that. Thing is, with a standard MVC application, a controller action always has it’s own url. With SitecoreMvc any page in Sitecore can use the same MVC Action over and over again, on different url’s. This is so different, it’ll be impossible to keep things cross-compatible.</p>
<p>First, we need to add 2 files to our MVC solution. One of the files will extend the default HtmlHelper with some extra methods to easily create links to Sitecore items. The other file will add support for wildcard items (remember that *Id and *Genre items you’ve created?). Download <a href="http://www.chrisvandesteeg.nl/download/Extensions.cs">Extensions.cs</a> and <a href="http://www.chrisvandesteeg.nl/download/WildcardValueProvider.cs">WildcardValueProvider.cs</a> and add them to your solution (eg. in a Helpers folder) (these files will ofcourse also be part of the next BoC.Sitecore.MVC release, but we’re still working without external libs in this tutorial)<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image14.png" width="221" height="57"/></p>
<p>In your global.asax, register the wildcardvalueprovider in the application_start:<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image15.png" width="724" height="86"/></p>
<p>Now, go change all the links in the project….</p>
<p>Open Views/Store/GenreMenu.cshtml. Modify the @Html.ActionLink in there, to the following:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image16.png" width="684" height="85"/></p>
<p>See how we’ve mapped Genre as a parameter? The wildcard resolver will pick that up. </p>
<p>In Views/Home/Index.cshtml and Views/Store/Browse.cshtml change the action Url.Action to <br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image17.png" width="683" height="26"/><br />This is the alternate method to set the wildcard item (*Id): by providing an anonymous object with the correct values</p>
<p>The Html.ActionLink in Views/Store/Index.cshtml to<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image18.png" width="652" height="30"/></p>
<p>The Html.ActionLink in Views/ShoppingCart/CartSummary.cshtml to <br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image19.png" width="1003" height="26"/></p>
<p>In Views/ShoppingCart/Index.cshtml, change the $.post(&#8220;/ShoppingCart/RemoveFromCart&#8221; to<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image24.png" width="619" height="45"/><br />(See how this will go directly to MVC! This won’t hit any Sitecore item, hence the url would become /musicstore_api/shoppingcart/removefromcart).</p>
<p>In the same file, replace the checkout Html.ActionLink with<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image20.png" width="597" height="31"/><br />and the details Html.ActionLink to <br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image22.png" width="775" height="26"/></p>
<p>In Views/ShoppingCart/Complete.cshtml change the Html.ActionLink to<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image27.png" width="442" height="28"/></p>
<p>In Controllers/ShoppingCartController.cs, in the AddToCart method, change the RedirectToAction to<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image23.png" width="465" height="45"/></p>
<p>and, the last one, in Controllers/CheckoutController.cs, in the AddressAndPayment method, change the RedirectToAction to<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image24.png" width="749" height="32"/></p>
<h3></h3>
<h4>Step 13 &#8211; Remove authorization</h4>
<p>As a last step remove the Authorize attribute on the CheckoutController. In this tutorial, we’ll not be setting up Account related stuff, it’ll be taken care with in the follow-up of this post.</p>
<h4><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image71.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image7" border="0" alt="image7" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/07/image7_thumb.png" width="429" height="56"/></a></h4>
<h4>Step 14 &#8211; Run</h4>
<p>Now run your project again! Everything but Account-related stuff should work fine now! Add albums to your cart, check out, etc.</p>
<h4>Conclusion</h4>
<p>That concludes this tutorial for now. It should give you a good idea on how to get MVC up and running for your Sitecore projects.In the next blog post about Sitecore &amp; MVC, I will explain how to use the Sitecore security in this MVC Musicstore and we’ll get rid of the external database by creating Sitecore items for the albums. I will try to add the new Model’s feature in Sitecore 6.6 for that. The albums will the be editable using both the Sitecore content-editor AND page-editor.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/chrisvandesteeg?a=D57xdC05HJE:3f4-S6ZO9zY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/chrisvandesteeg?d=yIl2AUoC8zA" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2012/07/19/mvc-musicstore-for-sitecore-6-6/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://www.chrisvandesteeg.nl/2012/07/19/mvc-musicstore-for-sitecore-6-6/</feedburner:origLink></item>
		<item>
		<title>Sitecore MVC Music Store</title>
		<link>http://feedproxy.google.com/~r/chrisvandesteeg/~3/RYgLfgv8vIY/</link>
		<comments>http://www.chrisvandesteeg.nl/2012/05/17/sitecore-mvc-music-store/#comments</comments>
		<pubDate>Thu, 17 May 2012 05:23:27 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[sitecore]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/?p=320</guid>
		<description><![CDATA[In my last blog post about using the MVC Framework inside Sitecore, I announced that I’d write another blog post on how to actually create a real world application with MVC inside Sitecore. The first blog post was just a proof of concept, creating a real world application with it, helps completing the code. In [...]]]></description>
				<content:encoded><![CDATA[<p>In my last blog post about using the MVC Framework inside Sitecore, I announced that I’d write another blog post on how to actually create a real world application with MVC inside Sitecore. The first blog post was just a proof of concept, creating a real world application with it, helps completing the code.</p>
<p>In the meantime, Sitecore <a href="http://www.sitecore.net/Community/Business-Blogs/Technical-Trends/Posts/2012/06/MVC-and-Sitecore-651-Overview.aspx" target="_blank">has announced</a> that it will support MVC in Sitecore version 6.5.1. Great news! I got a sneak preview of what they’ve made, looks great. From what I’ve seen, this tutorial won’t have to change much when they’ve released the official version. I’ll update the tutorial as soon as 6.5.1 will be released.</p>
<p>Since Microsoft has already created a nice tutorial for getting started with ASP.NET MVC : <a href="http://www.asp.net/mvc/tutorials/mvc-music-store" target="_blank">MVC Music Store tutorial</a>. I figured it’d also be a nice tutorial to get started with MVC inside Sitecore. It’s an easy to follow, small tutorial, which makes it easy to go through for both experts and beginners in the world of MVC. Experts can just skip the parts explaining how MVC itself works and go straight to the action. For beginners, the entire tutorial takes less then 2 hours. It’ll be the best invested 2 hours of your programmer’s life so far <img src='http://www.chrisvandesteeg.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ! </p>
<p>Once you have completed the Microsoft tutorial, the steps in this blog-post will help you transform it to a Sitecore project.</p>
<h4>Step 1 – complete the tutorial</h4>
<p>First, follow the entire tutorial (or if you’re an expert on MVC already, just download the package:<a href="http://mvcmusicstore.codeplex.com/">http://mvcmusicstore.codeplex.com/</a>)</p>
<h4>Step 2 – copy contents</h4>
<p>Copy the wwwroot contents of the mvcmusicstore project into the wwwroot of an existing Sitecore project (or create a new one first), but <strong>SKIP the web.config </strong>files! Note that you should copy the web-files to the web folder of your sitecore project! (if you downloaded the package, the web-content is inside the ‘MvcMusicStore’ folder inside the zip file)</p>
<p>Now open the Sitecore project in visual studio, and add the project you just copied to your solution (File –&gt; Add –&gt; Existing project).</p>
<h4>Step 3 – nuget package</h4>
<p>Install the NuGet package BoC.Sitecore.Mvc (not the starter app) to your just added project. You can do that either through the package manager console or through tools-&gt;library package manager-&gt;Manage NuGet Packages for Solution…</p>
<p>This will modify your web.config to allow MVC applications inside your sitecore website, and will add the BoC.Sitecore.MVC reference which holds all the MVC magic.</p>
<h4>Step 4 – connectionstrings</h4>
<p>Now, copy the connectionstring in the web.config of the original created MVCMusicStore project, to the App_Config\Connectionstrings.config inside your sitecore solution.</p>
<p>If you now run your application, and everything went fine, your application should work exactly the same as when you finished the tutorial. (Note: if you downloaded the sample code instead of making your own, and you run in to the error code&nbsp; <em>“Unable to find the requested .Net Framework Data Provider.&nbsp; It may not be installed.”</em>, you need to install <a href="http://www.microsoft.com/en-us/download/details.aspx?id=17876" target="_blank">MS Sql Compact CE 4.0</a>)</p>
<p>These first 4 steps were the steps required to get an existing MVC application working inside the sitecore wwwroot. Now we’ll start modifying the existing app to become an application fully powered by sitecore!</p>
<h4>Step 5 – Global.asax</h4>
<p>Running the application worked just fine, but there’s no sitecore magic somewhere in the pipeline, so let’s add that. First, we’ll modify the default route in global.asax.cs. You can do that by adding any static string value in front of the default route. I chose ‘musicstore_api’. Doing this will make all your controller actions accessible through /musicstore_api/home/index, this could come in handy for stuff you need to access without going through sitecore (eg. ajax calls, delete actions, etc)</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image.png" width="544" height="212"/></p>
<h4>Step 6 – Create ‘GetLayout’ controller action and view</h4>
<p>Using BoC.Sitecore.Mvc, if you want a Razor view as your layout, you’ll have to load it through a controller action. If you don’t like creating a controller action for just loading the base layout, you could use Robert Jongkind’s <a href="http://dotnetminute.blogspot.nl/2011/06/razorforsitecore-module-enable-razor.html" target="_blank">RazorForSitecore module</a>, it will all mix and match just fine. Sitecore 6.5.1’s version of MVC will also support picking a Razor view without a controller as your layout..</p>
<p>For now however, we’ll stick to using just the SitecoreMVC way. Open your HomeController.cs file and add new action called ‘DefaultLayout’. The only thing that action should do, is return View():</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image1.png" width="332" height="88"/></p>
<p>Also create the accompanying view, with just 1 line telling Sitecore it can render a placeholder with key “main” in this view. (Html.SitecorePlaceholder is an extension method inside BoC.Sitecore.MVC)</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image2.png" width="312" height="31"/></p>
<h4>Step 7 – Create Sitecore templates</h4>
<p>Run your application, and go the the Sitecore desktop (/sitecore/shell/default.aspx) and open the template manager.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Screenshot - 3-6-2012 , 14_14_50" border="0" alt="Screenshot - 3-6-2012 , 14_14_50" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/Screenshot-3-6-2012-14_14_50.png" width="443" height="227"/>&nbsp;</p>
<p>Add a new template folder underneath ‘Templates\User defined’ called ‘MVC MusicStore. Underneath that new folder, add a new template.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image3.png" width="421" height="348"/></p>
<p>Call the new template ‘Default page’ and just let the base template field as it is. Click next, next, finish.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image4.png" width="460" height="232"/></p>
<p>Select your new ‘Default page’ item in the tree, and on the ribbon ‘Builder options’ click the ‘Standard values’ button in the template section.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image5.png" width="123" height="64"/></p>
<p>And next on the ‘Presentation’ ribbon, click the ‘Details’ button in the layout section</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image6.png" width="94" height="64"/></p>
<p>This will open the layout details wizard:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image7.png" width="530" height="380"/></p>
<p>Here, click the Edit-button under the ‘Default’ section (marked with a red border in the screenshot above), which will open the “Device Editor” popup:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image8.png" width="391" height="182"/></p>
<p>In the dropdown, choose the ‘DefaultLayout’ MVC action underneath the Home controller and click OK twice</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image9.png" width="167" height="209"/></p>
<h4>Step 8 – Create sitecore items</h4>
<p>Based on our just created ‘Default page’ template, we’re now going to add the Sitecore items based on this template.</p>
<p>Open up the content editor in sitecore, and delete the exiting homepage item (/sitecore/content/home). Add a new Home item by click the ‘Content’ item with the right mouse button and choosing ‘Insert –&gt; Insert from Template’.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image10.png" width="353" height="202"/></p>
<p>Call the item Home and pick our just created ‘Default page’ template as it’s template</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image11.png" width="347" height="318"/></p>
<p>Using this same template, create the following tree inside Sitecore:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image12.png" width="276" height="210"/></p>
<p>Notice the * in front of Genre and Id…. these are wildcard mappings! The <strong>name</strong> of the items should be * and the <strong>displayname</strong> *Genre and *Id.</p>
<h4>Step 9 – Attach controller actions</h4>
<p>On these pages, we’ll attach the appropiate MVC Action. Start with the Home item. Click on it in the tree, and open the ‘Presentation’ ribbon. Now click on the details button:</p>
<p>&nbsp;<img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image13.png" width="94" height="64"/><br />This will open the layout popup</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image14.png" width="494" height="386"/></p>
<p>Now click the Edit-button under the ‘Default’ section (marked with a red border in the screenshot above), which will open the “Device Editor” popup <img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image15.png" width="440" height="226"/></p>
<p>Click the controls tab, and choose ‘Add’. That will bring up the ‘Select a rendering’ window.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image16.png" width="469" height="296"/></p>
<p>Choose MVC Actions/Home/Index and enter ‘main’ as the placeholder name (remember we added that $Html.SitecorePlaceholder(“main”) to DefaultLayout.cshtml?). Click on Select, and then on OK twice to save all your changes.</p>
<p>Now do the same for all other pages you’ve created except the ‘checkout’ page (that is just a placeholder). The other pages should get the following controls:</p>
<ul>
<li>Checkout –&gt; MVC Actions/Checkout/Complete  </li>
<li>Checkout/AddressAndPayment –&gt; MVC Actions/Checkout/AddressAndPayment  </li>
<li>ShoppingCart –&gt; MVC Actions/ShoppingCart/Index  </li>
<li>Store –&gt; MVC Actions/Store/Index  </li>
<li>Store/Browse –&gt; MVC Actions/Store/Browse  </li>
<li>Store/Browse/*Genre –&gt; MVC Actions/Store/Browse  </li>
<li>Store/Details –&gt; MVC Actions/Store/Details  </li>
<li>Store/Details/*Id –&gt; MVC Actions/Store/Details </li>
</ul>
<h4>Step 10 – Publish &amp; test</h4>
<p>Now, publish your entire site (! beware that if you’re using the sample database with the sample item template, that there is a worfklow attached to the new items by default… you need to approve them before publishing). After publishing, you can go checkout the homepage of your website.</p>
<p>Hey! the navigation menu and logo are shown twice!</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image17.png" width="822" height="547"/></p>
<h4>Step 11 – Modify viewstart</h4>
<p>The reason for the page being displayed twice, is because the default MVC Musicstore project does not take into account that the views can be accessed as a child-action. Adding the actions as a sublayout inside our sitecore pages, makes the actions being rendered as childactions. To skip the layout being rendered in child mode, open Views/_ViewStart.cshtml and modify the one line that’s in there to:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image18.png" width="405" height="109"/></p>
<p>Save the file, and check the homepage again: Looking much better!</p>
<h4>Step 12 – Modify Links</h4>
<p>Though the app looks good now, all links are pointing to the /musicstore_api folder. Even though that will work just fine, that’s the native MVC you’re calling then. To point all links to the sitecore versions, we’ll have to change all link renderings. This is the most dramatic change in an existing MVC app. In fact, we’ll break compatibility here, since the links will become Sitecore specific. I haven’t figured out a way to keep this compatible. Then again, I don’t think you’d ever even want that. Thing is, with a standard MVC application, a controller action always has it’s own url. With SitecoreMvc any page in Sitecore can use the same MVC Action over and over again, on different url’s. This is so different, it’ll be impossible to keep things cross-compatible.</p>
<p>Open Views/Store/GenreMenu.cshtml. Modify the @Html.ActionLink in there, to the following:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image19.png" width="615" height="69"/></p>
<p>See how we’ve mapped Genre as a parameter? The wildcard resolver will pick that up. We could have also placed the name in the path attribute, that would resolve just the same:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image20.png" width="554" height="69"/></p>
<p>Now do the same for all other links in the project. In Views/Home/Index.cshtml and Views/Store/Browse.cshtml change the action Url.Action to <br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image21.png" width="815" height="37"/></p>
<p>The Html.ActionLink in Views/Store/Index.cshtml to<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image22.png" width="648" height="48"/></p>
<p>The Html.ActionLink in Views/ShoppingCart/CartSummary.cshtml to <br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image23.png" width="513" height="46"/></p>
<p>In Views/ShoppingCart/Index.cshtml, change the $.post(&#8220;/ShoppingCart/RemoveFromCart&#8221; to<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image24.png" width="619" height="45"/><br />(See how this will go directly to MVC! This won’t hit any Sitecore item, hence the url would become /musicstore_api/shoppingcart/removefromcart).</p>
<p>In the same file, replace the checkout Html.ActionLink with<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image25.png" width="739" height="22"/><br />and the details Html.ActionLink to <br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image26.png" width="818" height="33"/></p>
<p>In Views/ShoppingCart/Complete.cshtml change the Html.ActionLink to<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image27.png" width="442" height="28"/></p>
<p>In Controllers/ShoppingCartController.cs, in the AddToCart method, change the RedirectToAction to<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image28.png" width="475" height="48"/></p>
<p>and, the last one, in Controllers/CheckoutController.cs, in the AddressAndPayment method, change the RedirectToAction to<br /><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image29.png" width="692" height="34"/></p>
<h3></h3>
<h4>Step 13 &#8211; Remove authorization</h4>
<p>As a last step remove the Authorize attribute on the CheckoutController. In this tutorial, we’ll not be setting up Account related stuff, it’ll be taken care with in the follow-up of this post.</p>
<h4><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/06/image30.png" width="429" height="56"/></h4>
<h4>Step 14 &#8211; Run</h4>
<p>Now run your project again! Everything but Account-related stuff should work fine now! Add albums to your cart, check out, etc.</p>
<h4>Conclusion</h4>
<p>That concludes this tutorial for now. It should give you a good idea on how to get MVC up and running for your Sitecore projects.In the next blog post about Sitecore &amp; MVC, I will explain how to use the Sitecore security in this MVC Musicstore and we’ll get rid of the external database by creating Sitecore items for the albums. The albums will the be editable using both the Sitecore content-editor AND page-editor. So watch this blog for the follow-up, though I’ll first write a post on an other topic.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/chrisvandesteeg?a=RYgLfgv8vIY:rQqOffz5mwg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/chrisvandesteeg?d=yIl2AUoC8zA" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2012/05/17/sitecore-mvc-music-store/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.chrisvandesteeg.nl/2012/05/17/sitecore-mvc-music-store/</feedburner:origLink></item>
		<item>
		<title>Sitecore MVC</title>
		<link>http://feedproxy.google.com/~r/chrisvandesteeg/~3/BlZaud3I7R8/</link>
		<comments>http://www.chrisvandesteeg.nl/2012/02/26/sitecore-mvc/#comments</comments>
		<pubDate>Sun, 26 Feb 2012 20:57:15 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[sitecore]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/?p=281</guid>
		<description><![CDATA[January 1st I started my new Job at eFocus, a full service internet company, at the department specialized in Sitecore development. I’d never worked with Sitecore before, so it was a complete new experience. Since I love the ASP.NET MVC way of development, I started looking if there was an option to use it for [...]]]></description>
				<content:encoded><![CDATA[<p>January 1st I started my new Job at <a href="http://www.efocus.nl" target="_blank">eFocus</a>, a full service internet company, at the department specialized in Sitecore development. I’d never worked with Sitecore before, so it was a complete new experience. Since I love the ASP.NET MVC way of development, I started looking if there was an option to use it for Sitecore development. Unfortunately I did not find any community effort to do so, except for blog posts on how to use Sitecore and an MVC project side-by-side. So I decided to try to create my own solution, since I would then have something fun to do while getting to know the ins and outs of Sitecore, something I felt obliged to do anyway.</p>
<p>In this blog post I&#8217;ll show you how to install and use my end-result of this proof of concept. In a follow-up, I&#8217;ll create a sample application with it. This first version is really just that: a proof of concept, just showing that it works. For example, this version includes a simple valueprovider for binding sitecore items to a model, but this is far from optimal. When creating a sample application, I’ll also be digging into modelbinding and other issues that’ll show up when creating an application. Perhaps I’ll conclude that its better to use something like <a href="http://trac.sitecore.net/CustomItemGenerator#" target="_blank">CustomItem generator</a> or <a href="http://www.glass.lu/" target="_blank">the glass project</a> and wrap one of those in a modelbinder, we’ll see (shoot your opinion about that in the comments!). I also only tested this on Sitecore 6.4, so it’ll probably only work on that version and up.</p>
<p>Now, let’s go to the code! To get started, open an existing Sitecore project (or create a new one) in Visual Studio. Now add the NuGet package BoC.Sitecore.MvcApp either through the package manager console or through tools-&gt;library package manager-&gt;Manage NuGet Packages for Solution&#8230;</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="VerySimpleWebsite - Manage NuGet Packages_2012-02-28_18-36-28" border="0" alt="VerySimpleWebsite - Manage NuGet Packages_2012-02-28_18-36-28" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/VerySimpleWebsite-Manage-NuGet-Packages_2012-02-28_18-36-28.png" width="904" height="604" /></p>
<p>The Sitecore Mvc starter app is the version I’ll use for this blog-post: it will add a basic mvc project to your solution to get started with. The other one (BoC.Sitecore.Mvc) will just add the dll + a config file to your current project, use this one if you want to set up your own Mvc project without any starting point.</p>
<p>Once you’ve installed the package, a new project named ‘yourproject’.mvcapp is added to your solution:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="emptysite - Microsoft Visual Studio_2012-02-28_18-40-50" border="0" alt="emptysite - Microsoft Visual Studio_2012-02-28_18-40-50" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/emptysite-Microsoft-Visual-Studio_2012-02-28_18-40-50.png" width="290" height="504" /></p>
<p>This is an empty ASP.NET MVC3 Razor project, with some stuff removed. The default web.config is removed, since we’ll have to use a modified version of Sitecore’s web.config and the account-stuff has been removed. As you can see, a default HomeController has been added, a default view and a default model (ItemView). Now, to see if BoC.Sitecore.Mvc works, let’s build the solution and open up the sitecore shell. Once logged in to your Sitecore shell, expand the tree items /sitecore/Layout and /sitecore/Layout/Layouts. You’ll see that underneath both, a new folder is added named ‘MVC Actions’. It’s in two places since you can use your MVC Actions both as Layout or as a rendering, more on that later.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Sitecore - Windows Internet Explorer_2012-02-28_19-02-43" border="0" alt="Sitecore - Windows Internet Explorer_2012-02-28_19-02-43" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/Sitecore-Windows-Internet-Explorer_2012-02-28_19-02-43.png" width="247" height="447" /></p>
<p>Let’s see what the action and view for Home/Index looks like, so we can now what to expect to see when we try to load them in sitecore. The action itself looks very simple:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="emptysite - Microsoft Visual Studio_2012-02-28_19-09-36" border="0" alt="emptysite - Microsoft Visual Studio_2012-02-28_19-09-36" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/emptysite-Microsoft-Visual-Studio_2012-02-28_19-09-36.png" width="414" height="163" /></p>
<p>It expects an item of type ItemView and just passes that on to the view. As mentioned earlier, I added a simple valueprovider that will try to resolve any parameter named “item” with field-values from the current sitecore item (the current sitecore item by default is the context.item, unless you provided a datasource for the rendering). The model by default only includes the property DisplayName of the type RenderingString:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="emptysite - Microsoft Visual Studio_2012-02-28_19-14-05" border="0" alt="emptysite - Microsoft Visual Studio_2012-02-28_19-14-05" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/emptysite-Microsoft-Visual-Studio_2012-02-28_19-14-05.png" width="486" height="105" /></p>
<p>RenderingString is a special type added by BoC.Sitecore.Mvc : it will call RenderField when outputted in html so you can use the page editor. You could also change this to ‘public string DisplayName {get; set; }’ to have it filled with the normal string value. Since DisplayName is not editable in the page editor, and thus we cannot see the difference between RenderingString and normal String, let’s change this property to Title like so:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="emptysite - Microsoft Visual Studio_2012-02-28_19-19-04" border="0" alt="emptysite - Microsoft Visual Studio_2012-02-28_19-19-04" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/emptysite-Microsoft-Visual-Studio_2012-02-28_19-19-04.png" width="428" height="85" /></p>
<p>In our case we’ll use the ‘Sample Item’ template from the default setup, which has a Title field. If your item does not have a Title field, you’ll have to pick some other field name of course. </p>
<p>Now, open up the view in Views/Home/Index.cshtml: </p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="emptysite - Microsoft Visual Studio_2012-02-28_20-05-05" border="0" alt="emptysite - Microsoft Visual Studio_2012-02-28_20-05-05" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/emptysite-Microsoft-Visual-Studio_2012-02-28_20-05-05.png" width="314" height="50" /></p>
<p>The view still uses DisplayName, so we have to change that as well:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="emptysite - Microsoft Visual Studio_2012-02-28_20-08-02" border="0" alt="emptysite - Microsoft Visual Studio_2012-02-28_20-08-02" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/emptysite-Microsoft-Visual-Studio_2012-02-28_20-08-02.png" width="313" height="49" /></p>
<p>When the view will be fully rendered (thus not through a RenderChildAction), the view uses the ‘masterpage’ Views/Shared/_Layout.cshtml:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="emptysite - Microsoft Visual Studio_2012-02-28_20-14-09" border="0" alt="emptysite - Microsoft Visual Studio_2012-02-28_20-14-09" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/emptysite-Microsoft-Visual-Studio_2012-02-28_20-14-09.png" width="886" height="622" /></p>
<p>As you can see there is a special HtmlHelper extension used here: @Html.RenderPlaceholder(“main”) which is the equivalent of &lt;sc:placeholder Key=”main” runat=”server” /&gt; for the aspx version.</p>
<p>Now, compile your changes, and go back to the sitecore shell. Underneath the Homepage, add a new Sample Item template called ‘My new sample item’ and click the ‘Layout Details’ button in the ‘Presentation’ Ribbon.&#160; In the dialog that opens, click on ‘edit’.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Sitecore MVC - Windows Live Writer_2012-02-28_20-11-17" border="0" alt="Sitecore MVC - Windows Live Writer_2012-02-28_20-11-17" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/Sitecore-MVC-Windows-Live-Writer_2012-02-28_20-11-17.png" width="833" height="631" /></p>
<p>In the next dialog, click on the layout to pick the MVC Actions / Home / Index layout</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Sitecore -- Dialoogvenster van webpagina_2012-02-28_20-20-37" border="0" alt="Sitecore -- Dialoogvenster van webpagina_2012-02-28_20-20-37" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/Sitecore-Dialoogvenster-van-webpagina_2012-02-28_20-20-37.png" width="513" height="633" /></p>
<p>Now, save all modifications by click ‘OK’ twice.</p>
<p>Now in the ribbon presentation, click on the ‘preview’ button to see our new page.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Sitecore - Windows Internet Explorer_2012-02-28_20-26-29" border="0" alt="Sitecore - Windows Internet Explorer_2012-02-28_20-26-29" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/Sitecore-Windows-Internet-Explorer_2012-02-28_20-26-29.png" width="1099" height="452" /></p>
<p>And there it is! Our MVC rendered sitecore item. The page still holds all the other renderings from the original Sample Item template including the nested <em>Sample Sublayout.ascx</em> the <em>Sample Inner Sublayout.ascx </em>and the <em>sample rendering.xslt. </em>So now we have an MVC rendered razor layout, holding asp.net usercontrols with an xslt rendering! You can mix-and-match those all together, how cool is that! </p>
<p>The item’s title is displayed twice, since our ‘Layout’ renders the title also, remember (the Home/Index.cshtml ouputs the title, and we’ve picked that as our Layout for the sitecore item). To see that the page editor also still works (even for the razor code), click on the ‘page editor’ button in the ‘Publish’ ribbon.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="httplocalhost56325sc_mode=edit&amp;sc_itemid=%7b46A6E270-FD57-4A02-9BBE-4B6AB2_2012-02-28_20-35-35" border="0" alt="httplocalhost56325sc_mode=edit&amp;sc_itemid=%7b46A6E270-FD57-4A02-9BBE-4B6AB2_2012-02-28_20-35-35" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/httplocalhost56325sc_modeeditsc_itemid7b46A6E270-FD57-4A02-9BBE-4B6AB2_2012-02-28_20-35-35.png" width="636" height="588" /></p>
<p>Modify the fields, add some extra renderings, it all still works. To show off an extra mix-and-match, now let’s also add our action as rendering to the existing asp.net based homepage.</p>
<p>Click on the homepage-treeitem and click on the ‘Layout details’ button on the ‘Presentation’ ribbon. In the popup dialog, click on ‘edit’ and then, in the next popup dialog, click on controls.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Sitecore -- Dialoogvenster van webpagina_2012-02-28_20-39-30" border="0" alt="Sitecore -- Dialoogvenster van webpagina_2012-02-28_20-39-30" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/Sitecore-Dialoogvenster-van-webpagina_2012-02-28_20-39-30.png" width="497" height="269" /></p>
<p>Now, click the add button. In the next popup dialog, select MVCActions/Home/Index and add it to placeholder ‘/main/centercolumn/content’</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Sitecore -- Dialoogvenster van webpagina_2012-02-28_20-41-12" border="0" alt="Sitecore -- Dialoogvenster van webpagina_2012-02-28_20-41-12" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/Sitecore-Dialoogvenster-van-webpagina_2012-02-28_20-41-12.png" width="409" height="395" /></p>
<p>Click on select, and then twice on OK to save this new addition. Now, on our preview pane, we see an extra Title appear!</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Sitecore - Windows Internet Explorer_2012-02-28_20-44-43" border="0" alt="Sitecore - Windows Internet Explorer_2012-02-28_20-44-43" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2012/02/Sitecore-Windows-Internet-Explorer_2012-02-28_20-44-43.png" width="525" height="472" /></p>
<p>This is our Views/Home/Index.cshtml ! Since the action is now added to the page as a rendering instead of being used as a layout, the /Views/Shared/_Layout.cshtml is not used. This is because this action is now being rendered by calling MVC’s RenderChildAction. Child actions never have a layout.</p>
<p>Now just go ahead and do some mixing of different options for yourself, you could try a different viewengine (aspx, spark viewengine) for example, works just fine. A little extra nice-to-know is that you can add a DescriptionAttribute to your controllers and/or actions to have them show up differently in sitecore. ({0} is thereby replaced with the original name).</p>
<p>I hope you’ll all enjoy playing with MVC within Sitecore and get some great ideas about it while you’re at it. Please leave all your great ideas and suggestions in the comments.</p>
<p>If you want to checkout the source, you can find that at github: <a title="https://github.com/csteeg/BoC.Sitecore.MVC" href="http://github.com/csteeg/BoC.Sitecore.MVC">http://github.com/csteeg/BoC.Sitecore.MVC</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/chrisvandesteeg?a=BlZaud3I7R8:XW2ZjX4vZWk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/chrisvandesteeg?d=yIl2AUoC8zA" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2012/02/26/sitecore-mvc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.chrisvandesteeg.nl/2012/02/26/sitecore-mvc/</feedburner:origLink></item>
		<item>
		<title>Compile your asp.net mvc Razor views into a seperate dll</title>
		<link>http://feedproxy.google.com/~r/chrisvandesteeg/~3/hLzcukfjB2U/</link>
		<comments>http://www.chrisvandesteeg.nl/2010/11/22/embedding-pre-compiled-razor-views-in-your-dll/#comments</comments>
		<pubDate>Mon, 22 Nov 2010 16:05:40 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/?p=242</guid>
		<description><![CDATA[NOTE: THE GENERATOR HAS EVOLVED SINCE THIS POST.Although the post is still worth reading, please go to http://razorgenerator.codeplex.com/ for the most up to date version. Inspired by David Ebbo’s blog post ‘Turn your Razor helpers into reusable libraries’ I wanted to be able to embed compiled Razor views in a dll. This would allow for [...]]]></description>
				<content:encoded><![CDATA[<p><strong>NOTE: THE GENERATOR HAS EVOLVED SINCE THIS POST.Although the post is still worth reading, please go to <a href="http://razorgenerator.codeplex.com/">http://razorgenerator.codeplex.com/</a> for the most up to date version.</strong></p>
<p>Inspired by <a href="http://blogs.msdn.com/b/davidebb/">David Ebbo</a>’s blog post ‘<a href="http://blogs.msdn.com/b/davidebb/archive/2010/10/27/turn-your-razor-helpers-into-reusable-libraries.aspx">Turn your Razor helpers into reusable libraries</a>’ I wanted to be able to embed compiled Razor views in a dll. This would allow for easy distribution of asp.net mvc ‘modules’ that have their default views embedded, but allowing you to place files in your ‘views’ folder to override those default views. </p>
<p>To generate the c# code for the views, I just started out with David Ebbo’s single file generator and modified it to generate views instead of helpers only. To do this, there had to be a WebRazorHostFactory that knew about all the mvc stuff (what dll’s to reference, what namespaces to use, etc) .I could either choose to include all that information statically in the code, or I could look for a web.config in the same project and let the WebRazorHostFactory use that config. I chose the latter option, so that everyone can easily change the WebRazorHostFactory behavior&#160; by adding a web.config file to their project.</p>
<p>Next, I started figuring out how the PageVirtualPathAttribute inside System.Web.Webpages.dll is used by Microsoft. I found out that it is used when you call ApplicationPart.Register and after that call, there’s not much you can use of this functionality without some heavy reflection. I know it’s the wrong path to choose, but did it anyway. I ended up creating a ViewEngine calling into ApplicationPart’s internal methods to output compiled views. It worked, but I didn’t like it much: there had to be a better way.</p>
<p>I then tried if I could hook into the BuildManager stuff that asp.net mvc uses to generate the views. It was actually much easier then expected, now why didn’t I go on that path the first time!</p>
<p>I ended up creating </p>
<ul>
<li>a CompiledRazorBuildProvider, which inherits from the default RazorBuildProvider,</li>
<li>a CompiledVirtualPathProvider which returns a CompiledVirtualFile if it decides that a compiled view should be used</li>
<li>and a ApplicationPartRegistry, which registers which compiled views are available.</li>
</ul>
<p>To view the source, head over to </p>
<ul>
<li><a href="https://github.com/csteeg/BoC/tree/master/Src/Commons.Web.PrecompiledViews/">https://github.com/csteeg/BoC/tree/master/Src/Commons.Web.PrecompiledViews/</a> – for the classes mentioned</li>
<li><a href="https://github.com/csteeg/BoC/tree/master/Src/RazorSingleFileGenerator/">https://github.com/csteeg/BoC/tree/master/Src/RazorSingleFileGenerator/</a> – for David Ebbo’s modfied file generator</li>
</ul>
<p>To just get started without viewing the source, read on, I will explain step by step how to use this library with some screenshots.</p>
<p>If you have improvements, fork the project on GitHub and let me know! If you have suggestions for improvement, just drop it in the comments.</p>
<h3>Step 1: Install the FileGenerator</h3>
<p>Download and install the Visual Studio extension: <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/f28290ce-d987-4f91-b034-707031e10ce6/file/39295/0/RazorSingleFileGenerator.vsix">http://visualstudiogallery.msdn.microsoft.com/en-us/f28290ce-d987-4f91-b034-707031e10ce6/file/39295/0/RazorSingleFileGenerator.vsix</a></p>
<h2></h2>
<h3>Step 2: Create new mvc project</h3>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb.png" width="959" height="664" /></a></p>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image1.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb1.png" width="651" height="584" /></a></p>
<h3></h3>
<h3>Step 3: Add a class library to hold the views</h3>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image2.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb2.png" width="539" height="566" /></a></p>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image3.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb3.png" width="959" height="664" /></a></p>
<h3>Step 4: Cut your Models &amp; Views folders</h3>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image7.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb7.png" width="674" height="535" /></a></p>
<h3></h3>
<h3>Step 5: Paste them into the just created Class Library</h3>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image8.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb8.png" width="629" height="466" /></a></p>
<h3>Step 6: Copy the website’s web.config file</h3>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image9.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb9.png" width="643" height="287" /></a></p>
<h3>Step 7: Paste that web.config file into the class library</h3>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image10.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb10.png" width="701" height="704" /></a></p>
<h3>Step 8: Select all your .cshtml files in the class library and set the Custom Tool to ‘MvcRazorClassGenerator’</h3>
<p><em>Does anyone have a suggestion on improving this step??</em></p>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image6.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb6.png" width="654" height="391" /></a></p>
<h3>Step 9: Build your class library</h3>
<h3>Step 10: Add your class library to the references of the web application</h3>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image11.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb11.png" width="367" height="171" /></a></p>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image12.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb12.png" width="565" height="450" /></a></p>
<h3>Step 11: Add ‘Commons.web.mvc.precompiledviews.dll’ as a reference to your website</h3>
<p><em>this dll is copied to the class library’s output folder (in this case ../EmbeddedViews/bin/debug&#8217;)</em></p>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image13.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb13.png" width="565" height="450" /></a></p>
<h3>Step 12: Register your views by adding a line to the application_start in global.asax.cs</h3>
<h3></h3>
<h3></h3>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image14.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2010/11/image_thumb14.png" width="456" height="232" /></a></p>
<h3></h3>
<h3>Step 13: Run your website!</h3>
<p>Now, you will see the normal default website, even though there aren’t any views in your website path!</p>
<p>If you wish to override some views, just create the normal folders (eg /Views/Home) and add your views there, but don’t forget to copy back the deleted /Views/web.config back into your project then!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/chrisvandesteeg?a=hLzcukfjB2U:O0AbPSW16bs:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/chrisvandesteeg?d=yIl2AUoC8zA" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2010/11/22/embedding-pre-compiled-razor-views-in-your-dll/feed/</wfw:commentRss>
		<slash:comments>106</slash:comments>
		<feedburner:origLink>http://www.chrisvandesteeg.nl/2010/11/22/embedding-pre-compiled-razor-views-in-your-dll/</feedburner:origLink></item>
		<item>
		<title>HappyBirthday app – Vodafone App Star Country winner</title>
		<link>http://feedproxy.google.com/~r/chrisvandesteeg/~3/mex4vZOs2RQ/</link>
		<comments>http://www.chrisvandesteeg.nl/2010/05/05/happybirthday-app-vodafone-app-star-country-winner/#comments</comments>
		<pubDate>Wed, 05 May 2010 20:25:27 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[vf360]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/?p=217</guid>
		<description><![CDATA[I&#8217;m very (very!) happy to inform you all that my mobile app HappyBirthday! has won the 1st price at the Vodafone AppStar competition for the Netherlands. This also means, the app is now 1 of the eight apps in the the grand final! The first price of the finals is another &#8364; 75.000 !! So [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m very (very!) happy to inform you all that my mobile app <a href="http://www.chrisvandesteeg.nl/mobile-apps/happybirthday">HappyBirthday!</a> has won the 1st price at the Vodafone AppStar competition for the Netherlands. This also means, the app is now 1 of the eight apps in the the grand final! The first price of the finals is another &euro; 75.000 !!<br />
So I kindly ask you to all go vote at <a href="http://widget.developer.vodafone.com/nl/appstar/entries/671/voter/new">the Vodafone App Star website</a> and get me that first price! <img src='http://www.chrisvandesteeg.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>HappyBirthday is an app for the <a href="http://360.com">Vodafone 360</a> platform and helps you to never forget a birthday again.<br />
You can read more about the app at <a href="http://www.chrisvandesteeg.nl/mobile-apps/happybirthday">the details page of HappyBirthday!</a></p>
<p>The <a href="http://360.com">Vodafone 360 platform</a> is a new internet service for your mobile, PC and Mac. It brings your phone, email, chat and social network contacts together in one placeand runs on many many phones. You don&#8217;t need to have a vodafone account to join 360, anyone can join at <a href="http://360.com">http://360.com</a>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/chrisvandesteeg?a=mex4vZOs2RQ:X8zVpIHKvzE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/chrisvandesteeg?d=yIl2AUoC8zA" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2010/05/05/happybirthday-app-vodafone-app-star-country-winner/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.chrisvandesteeg.nl/2010/05/05/happybirthday-app-vodafone-app-star-country-winner/</feedburner:origLink></item>
		<item>
		<title>ASP.NET MVC, DynamicData, Domain-/RiaServices, Unity and NHibernate: Part 1</title>
		<link>http://feedproxy.google.com/~r/chrisvandesteeg/~3/UoAhXMvngZU/</link>
		<comments>http://www.chrisvandesteeg.nl/2009/07/13/aspnet-mvc-dynamicdata-domain-riaservices-unity-and-nhibernate-part-1/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 13:28:13 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[nhiberntate]]></category>
		<category><![CDATA[RiaServices]]></category>
		<category><![CDATA[unity]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/?p=91</guid>
		<description><![CDATA[I’ve been playing with RIAServices and DynamicData lately, and managed to combine these with NHibernate as ORM in an ASP.NET MVC project. For this project the following (extensive) list of libraries is used (all these libraries are included in the download): MS ASP.NET Mvc 1.0 Microsoft .NET RIA Services July 2009 Preview NHibernate 2.1.0CR1 NHibernate [...]]]></description>
				<content:encoded><![CDATA[<p>I’ve been playing with RIAServices and DynamicData lately, and managed to combine these with NHibernate as ORM in an ASP.NET MVC project.</p>
<p>For this project the following (extensive) list of libraries is used (all these libraries are included in the download):</p>
<ul>
<li><a href="http://go.microsoft.com/fwlink/?LinkId=144444" target="_blank">MS ASP.NET Mvc 1.0</a> </li>
<li><a href="http://go.microsoft.com/fwlink/?LinkId=144609" target="_blank">Microsoft .NET RIA Services July 2009 Preview</a> </li>
<li><a href="http://nhforge.org/blogs/nhibernate/archive/2009/07/05/good-morning-nhibernate-2-1-0cr1.aspx" target="_blank">NHibernate 2.1.0CR1</a> </li>
<li><a href="http://nhcontrib.svn.sourceforge.net/viewvc/nhcontrib/trunk/src/NHibernate.Linq/" target="_blank">NHibernate Linq</a> (latest trunk version) </li>
<li><a href="http://fluentnhibernate.org/" target="_blank">FluentNhibernate</a> (latest trunk version, patched to work with NHibernate 2.1.0CR1) </li>
<li><a href="http://www.codeplex.com/unity" target="_blank">MS Unity 1.2</a> </li>
<li><a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=18803" target="_blank">ASP.NET Dynamic Data MVC Preview</a> (since this project is pretty old, I had to modify it quite a bit, the source is included in the download) </li>
<li>I used <a href="http://blog.wekeroad.com/blog/make-visual-studio-generate-your-repository/" target="_blank">Rob Conery’s t4 templates</a> as the base to generate entities from the database. </li>
</ul>
<p>Besides using these libraries, I copied some code snippits from the <a href="http://www.codeplex.com/Kigg" target="_blank">Kigg</a> project, which has quite a nice codebase!</p>
<p>In the first part of this serie, I’ll show you how you can use these libraries along with my own code to scaffold the entire Northwind database in an mvc project. It’ll be totally hassle-free, I promise! It will generate classes from the database-schema and I will also show you how to override the default generated domainservices and repositories (yes, those are generated at runtime if you don’t specify your own!).</p>
<p>In the upcoming parts, I will add client-side validation and some ajax-love to the scaffold pages. In one of those parts I’ll also explain how my code works, and what it does. I’m also thinking about showing how to replace some parts of the library, since it’s very pluggable. I could for example replace the persistencelayer with Linq-to-Sql or replace the Depency part with StructureMap.</p>
<p>Although this sample shows you how to use an existing database, it would ofcourse be best if you could use the Model-first approach! Luckely nHibernate makes this very simple as well. If you create the entity files in your project and have them inherited from BaseEntity, all you have to do is add this line to your Application_Start:</p>
<p>new SchemaUpdate(IoC.Resolve&lt;Configuration&gt;).Execute(true, true);</p>
<p>Your database schema will be automatically updated if you change anything to your Model.</p>
<p>You can watch the screencast <a href="http://www.screentoaster.com/watch/stVUJXRExIR11XRF5YXFJbUVVc" target="_blank">here</a> and download the sample + dll’s <a href="http://code.google.com/p/webdotnet/downloads/list" target="_blank">here</a></p>
<p>&#160;</p>
<p> <object id='stVUJXRExIR11XRF5YXFJbUVVc' width='600' height='400' type='application/x-shockwave-flash' data='http://www.screentoaster.com/swf/STPlayer.swf'  codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0'><param name="movie" value="http://www.screentoaster.com/swf/STPlayer.swf" /><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="flashvars" value="video=stVUJXRExIR11XRF5YXFJbUVVc" /></object>
<p>For the next screencast, I’ll by a mic so I don’t have to subtitle it <img src='http://www.chrisvandesteeg.nl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/chrisvandesteeg?a=UoAhXMvngZU:_EqeD7bIWcw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/chrisvandesteeg?d=yIl2AUoC8zA" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2009/07/13/aspnet-mvc-dynamicdata-domain-riaservices-unity-and-nhibernate-part-1/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		<feedburner:origLink>http://www.chrisvandesteeg.nl/2009/07/13/aspnet-mvc-dynamicdata-domain-riaservices-unity-and-nhibernate-part-1/</feedburner:origLink></item>
		<item>
		<title>Making Unity work more like the others</title>
		<link>http://feedproxy.google.com/~r/chrisvandesteeg/~3/SqSo6RLpLUk/</link>
		<comments>http://www.chrisvandesteeg.nl/2009/04/16/making-unity-work-more-like-the-others/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 18:53:58 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[unity]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/?p=80</guid>
		<description><![CDATA[I love MS Unity as an IoC container, it has some great features. Though I found it to function incorrectly at two points (it&#8217;s not that the path chosen by the Unity team is incorrect, I just want/excpect it to act differently). The first thing that bothered me was the fact that Unity throws an [...]]]></description>
				<content:encoded><![CDATA[<p>I love <a href="http://www.codeplex.com/unity" target="_blank">MS Unity</a> as an IoC container, it has some great features. Though I found it to function incorrectly at two points (it&#8217;s not that the path chosen by the Unity team is incorrect, I just want/excpect it to act differently).  </p>
<p> The first thing that bothered me was the fact that Unity throws an exception when Resolve&lt;T&gt; is not able to resolve the given type: I’d prefer it to return null instead, hence most containers do that. The second, even more irritating point, was that ResolveAll&lt;T&gt; only returned the named instances/types instead of all registered types. In fact, Unity overwrites the default registration if your register a type multiple times. Eg:</p>
<pre class="c-sharp" name="code">    
Container.Register&lt;IMyInterFace, MyClass1&gt;();
Container.Register&lt;IMyInterFace, MyClass2&gt;();
</pre>
<p>would cause the MyClass1 registration to be removed. I’d like the MyClass1 to remain the default registration, and have ResolveAll&lt;IMyInterface&gt;() return both. I’m happy to tell you that it can be done!</p>
<p>When using an IoC container, it’s good practice to access it’s features through a generic wrapper class. For my projects, I use the wrapper from the <a href="http://www.codeplex.com/Kigg" target="_blank">Kigg</a> source code. If you access the container through a wrapper after you configured your container, it&#8217;ll be easy to replace it with a different container in the future.</p>
<p>My wrapper class looks like this:</p>
<pre class="c-sharp" name="code">    
public class UnityDependencyResolver : IDependencyResolver
{
    private readonly IUnityContainer container;

    public UnityDependencyResolver() : this(new UnityContainer())
    {
        var configuration = (UnityConfigurationSection) ConfigurationManager.GetSection("unity");
        if (configuration != null)
            configuration.Containers.Default.Configure(container);
    }
    
    public UnityDependencyResolver(IUnityContainer container)
    {
        Check.Argument.IsNotNull(container, "container");

        this.container = container;
        this.container.AddExtension(new TypeTrackingExtension());
        this.container.RegisterInstance&lt;IUnityContainer&gt;(container);
        this.container.RegisterInstance&lt;IDependencyResolver&gt;(this);
    }

    public IUnityContainer Container { get { return container; } }

    public void RegisterInstance&lt;T&gt;(T instance)
    {
        Check.Argument.IsNotNull(instance, "instance");

        container.RegisterInstance(instance);
    }

    public void RegisterType&lt;TFrom, TTo&gt;() where TTo : TFrom
    {
        container.RegisterType&lt;TFrom, TTo&gt;();
    }

    public void RegisterType(Type from, Type to)
    {
        Check.Argument.IsNotNull(from, "from");
        Check.Argument.IsNotNull(to, "to");

        container.RegisterType(from, to);
    }
    
    public void Inject&lt;T&gt;(T existing)
    {
        Check.Argument.IsNotNull(existing, "existing");

        container.BuildUp(existing);
    }
    
    public object Resolve(Type type)
    {
        Check.Argument.IsNotNull(type, "type");
        if (container.Configure&lt;TypeTrackingExtension&gt;().CanResolve(type))
        {
            return container.Resolve(type);
        }
        else
        {
            return null;
        }
    }
    
    public object Resolve(Type type, string name)
    {
        Check.Argument.IsNotNull(type, "type");
        if (Container.Configure&lt;TypeTrackingExtension&gt;().CanResolve(type, name))
        {
            return container.Resolve(type, name);
        }
        else
        {
            return null;
        }
    }

    
    public T Resolve&lt;T&gt;()
    {
        return (T) Resolve(typeof(T));
    }

    
    public T Resolve&lt;T&gt;(string name)
    {
        Check.Argument.IsNotEmpty(name, "name");
        return (T) Resolve(typeof(T), name);
    }

    
    public IEnumerable&lt;T&gt; ResolveAll&lt;T&gt;()
    {
        var namedInstances = container.ResolveAll&lt;T&gt;();
        var unnamedInstance = default(T);

        try
        {
            unnamedInstance = container.Resolve&lt;T&gt;();
        }
        catch (ResolutionFailedException)
        {
            //When default instance is missing
        }

        if (Equals(unnamedInstance, default(T)))
        {
            return namedInstances;
        }

        return new ReadOnlyCollection&lt;T&gt;(new List&lt;T&gt;(namedInstances) { unnamedInstance });
    }
    
    ~UnityDependencyResolver()
    {
        Dispose(false);
    }
    public void Dispose()
    {
        Dispose(true);
    }
    protected void Dispose(bool disposing)
    {
        if (disposing)
        {
            container.Dispose();
        }
    }
}
</pre>
<p>Though most methods are just direct wrappers for accessing the container itself, there are a few extra’s. For one, there’s the ResolveAll&lt;T&gt; method that returns both named and unnamed instances instead of only the named instances, that’s one problem fixed.</p>
<p>Secondly, you can see the Resolve methods use</p>
<p>if (Container.Configure&lt;TypeTrackingExtension&gt;().CanResolve(type, name))</p>
<p>It uses an UnityExtension to see if the Type can be resolved and it returns null if it can’t. This solution was provided by <a href="http://buksbaum.us" target="_blank">David Buksbaum</a> in his blog post <a href="http://buksbaum.us/2009/02/08/type-tracking-extension-for-unity/" target="_blank">Type Tracking Extension for Unity</a>. This extension is added to the container in this wrapper’s constructor.</p>
<p>I did modify David’s extension a little, to have it not overwrite the first registered type and to have CanResolve return true for types that can be initiated also (the original only returns true for types that have been registered). My version looks like this:</p>
<pre class="c-sharp" name="code">
public class TypeTrackingExtension : UnityContainerExtension
{
    private readonly Dictionary&lt;Type, HashSet&lt;string&gt;&gt; registeredTypes = new Dictionary&lt;Type, HashSet&lt;string&gt;&gt;();

    protected override void Initialize()
    {
        Context.Container.Configure&lt;UnityDefaultBehaviorExtension&gt;().Remove();
        Context.Container.Configure&lt;InjectedMembers&gt;().Remove();
        //we have to be the first in the chain
        Context.RegisteringInstance += OnNewInstance;
        Context.Registering += OnNewType;

        Context.Container.Configure&lt;UnityDefaultBehaviorExtension&gt;().InitializeExtension(Context);
        Context.Container.Configure&lt;InjectedMembers&gt;().InitializeExtension(Context);
    }

    public override void Remove()
    {
        base.Remove();
        Context.RegisteringInstance -= OnNewInstance;
        Context.Registering -= OnNewType;
    }
    private void OnNewInstance(object sender, RegisterInstanceEventArgs e)
    {
        HashSet&lt;string&gt; names;
        string name = string.IsNullOrEmpty(e.Name) ? string.Empty : e.Name;

        if (!registeredTypes.TryGetValue(e.RegisteredType, out names))
        { //  not found, so add it
            registeredTypes.Add(e.RegisteredType, new HashSet&lt;string&gt; { name });
        }
        else
        { //  already added type, so add name
            if (name == String.Empty &#038;&#038; names.Contains(name))
            {
                //default instance is already registered, let's give it a name so we can use ResolveAll() like it works in all other ioc containers
                name = e.Name = Guid.NewGuid().ToString();
            }
            names.Add(name);
        }
    }
    private void OnNewType(object sender, RegisterEventArgs e)
    {
        HashSet&lt;string&gt; names;
        string name = string.IsNullOrEmpty(e.Name) ? string.Empty : e.Name;
        if (!registeredTypes.TryGetValue(e.TypeFrom, out names))
        { //  not found, so add it
            registeredTypes.Add(e.TypeFrom, new HashSet&lt;string&gt; { name });
        }
        else
        { //  already added type, so add name
            if (name == String.Empty &#038;&#038; names.Contains(name))
            {
                //default instance is already registered, let's give it a name so we can use ResolveAll() like it works in all other ioc containers
                name = e.Name = Guid.NewGuid().ToString();
            }
            names.Add(name);
        }
    }

    /// &lt;summary&gt;
    /// Determines whether this type can be resolved as the default.
    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;&lt;/typeparam&gt;
    /// &lt;returns&gt;
    /// 	&lt;c&gt;true&lt;/c&gt; if this instance can resolve; otherwise, &lt;c&gt;false&lt;/c&gt;.
    /// &lt;/returns&gt;
    public bool CanResolve&lt;T&gt;()
    {
        return CanResolve(typeof(T), null);
    }
    /// &lt;summary&gt;
    /// Determines whether this type can be resolved as the default.
    /// &lt;/summary&gt;
    /// &lt;param name="type"&gt;The type.&lt;/param&gt;
    /// &lt;returns&gt;
    /// 	&lt;c&gt;true&lt;/c&gt; if this instance can resolve; otherwise, &lt;c&gt;false&lt;/c&gt;.
    /// &lt;/returns&gt;
    public bool CanResolve(Type type)
    {
        return CanResolve(type, null);
    }
    /// &lt;summary&gt;
    /// Determines whether this type can be resolved with the specified name.
    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;&lt;/typeparam&gt;
    /// &lt;param name="name"&gt;The name.&lt;/param&gt;
    /// &lt;returns&gt;
    /// 	&lt;c&gt;true&lt;/c&gt; if this instance can be resolved with the specified name; otherwise, &lt;c&gt;false&lt;/c&gt;.
    /// &lt;/returns&gt;
    public bool CanResolve&lt;T&gt;(string name)
    {
        return CanResolve(typeof (T), name);
    }

    /// &lt;summary&gt;
    /// Determines whether this type can be resolved with the specified name.
    /// &lt;/summary&gt;
    /// &lt;param name="type"&gt;The type.&lt;/param&gt;
    /// &lt;param name="name"&gt;The name.&lt;/param&gt;
    /// &lt;returns&gt;
    /// 	&lt;c&gt;true&lt;/c&gt; if this instance can be resolved with the specified name; otherwise, &lt;c&gt;false&lt;/c&gt;.
    /// &lt;/returns&gt;
    public bool CanResolve(Type type, string name)
    {
        if (isResolvableClass(type))
            return true;

        HashSet&lt;string&gt; names;
        if (registeredTypes.TryGetValue(type, out names))
        {
            return names.Contains(name ?? string.Empty);
        }
        return false;
    }

    private bool isResolvableClass(Type type)
    {
        return type.IsClass &#038;&#038; !type.IsAbstract;
    }
    /// &lt;summary&gt;
    /// Determines whether this instance can be resolved at all.
    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;&lt;/typeparam&gt;
    /// &lt;returns&gt;
    /// 	&lt;c&gt;true&lt;/c&gt; if this instance can be resolved at all; otherwise, &lt;c&gt;false&lt;/c&gt;.
    /// &lt;/returns&gt;
    public bool CanResolveAny&lt;T&gt;()
    {
        return CanResolveAny(typeof(T));
    }

    /// &lt;summary&gt;
    /// Determines whether this instance can be resolved at all.
    /// &lt;/summary&gt;
    /// &lt;param name="type"&gt;The type.&lt;/param&gt;
    /// &lt;returns&gt;
    /// 	&lt;c&gt;true&lt;/c&gt; if this instance can be resolved at all; otherwise, &lt;c&gt;false&lt;/c&gt;.
    /// &lt;/returns&gt;
    public bool CanResolveAny(Type type)
    {
        return isResolvableClass(type) || registeredTypes.ContainsKey(type);
    }

    /// &lt;summary&gt;
    /// Tries to resolve the type, returning null if not found.
    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;The type to try and resolve.&lt;/typeparam&gt;
    /// &lt;returns&gt;An object of type &lt;see cref="T"/&gt; if found, or &lt;c&gt;null&lt;/c&gt; if not.&lt;/returns&gt;
    public T TryResolve&lt;T&gt;()
    {
        return TryResolve&lt;T&gt;(default(T));
    }
    /// &lt;summary&gt;
    /// Tries to resolve the type with the specified of name, returning null if not found.
    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;The type to try and resolve.&lt;/typeparam&gt;
    /// &lt;param name="name"&gt;The name associated with the type.&lt;/param&gt;
    /// &lt;returns&gt;An object of type &lt;see cref="T"/&gt; if found, or &lt;c&gt;null&lt;/c&gt; if not.&lt;/returns&gt;
    public T TryResolve&lt;T&gt;(string name)
    {
        return TryResolve&lt;T&gt;(name, default(T));
    }
    /// &lt;summary&gt;
    /// Tries to resolve the type, returning null if not found.
    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;The type to try and resolve.&lt;/typeparam&gt;
    /// &lt;param name="defaultValue"&gt;The default value to return if type not found.&lt;/param&gt;
    /// &lt;returns&gt;An object of type &lt;see cref="T"/&gt; if found, or the &lt;see cref="defaultValue"/&gt; if not.&lt;/returns&gt;
    public T TryResolve&lt;T&gt;(T defaultValue)
    {
        if (!CanResolve&lt;T&gt;())
            return defaultValue;
        return Container.Resolve&lt;T&gt;();
    }
    /// &lt;summary&gt;
    /// Tries to resolve the type with the specified of name, returning null if not found.
    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;The type to try and resolve.&lt;/typeparam&gt;
    /// &lt;param name="name"&gt;The name associated with the type.&lt;/param&gt;
    /// &lt;param name="defaultValue"&gt;The default value to return if type not found.&lt;/param&gt;
    /// &lt;returns&gt;An object of type &lt;see cref="T"/&gt; if found, or the &lt;see cref="defaultValue"/&gt; if not.&lt;/returns&gt;
    public T TryResolve&lt;T&gt;(string name, T defaultValue)
    {
        if (!CanResolve&lt;T&gt;(name))
            return defaultValue;
        return Container.Resolve&lt;T&gt;(name);
    }
}
</pre>
<p>As you can see, I change the order of the event chain, by removing UnityDefaultBehaviorExtension from the Container, and then add it again later. This allows us to add a name to the type being registered. If a type is registered multiple times without a name given, a name is given in the form of a unique Guid</p>
<p>So now, if you do<br />
  </p>
<pre class="c-sharp" name="code">    
Container.Register&lt;IMyInterFace, MyClass1&gt;();
Container.Register&lt;IMyInterFace, MyClass2&gt;();

var wrapper = new UnityDependencyResolver(Container);
var classes = wrapper.ResolveAll&lt;IMyInterFace&gt;()
</pre>
<p>classes will contain both MyClass1 and MyClass2!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/chrisvandesteeg?a=SqSo6RLpLUk:rwlisTyvcsA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/chrisvandesteeg?d=yIl2AUoC8zA" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2009/04/16/making-unity-work-more-like-the-others/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.chrisvandesteeg.nl/2009/04/16/making-unity-work-more-like-the-others/</feedburner:origLink></item>
		<item>
		<title>Fluent NHibernate’s AutoPersistenceModel: I Love it!</title>
		<link>http://feedproxy.google.com/~r/chrisvandesteeg/~3/NJ_l7IiGpgk/</link>
		<comments>http://www.chrisvandesteeg.nl/2008/12/02/fluent-nhibernates-autopersistencemodel-i-love-it/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 20:52:04 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/2008/12/02/fluent-nhibernates-autopersistencemodel-i-love-it/</guid>
		<description><![CDATA[I checked out the latest version of Fluent NHibernate today and noticed the AutoPersistenceModel. I looked at the unit-tests to see what it’s supposed to do and I loved what I saw… Let’s say you have a 2 simple classes like this: Now, in the global.asax’s init (assuming a web application), we can configure NHibernate [...]]]></description>
				<content:encoded><![CDATA[<p>I checked out the latest version of <a href="http://code.google.com/p/fluent-nhibernate/">Fluent NHibernate</a> today and noticed the AutoPersistenceModel. I looked at the unit-tests to see what it’s supposed to do and I loved what I saw…</p>
<p>Let’s say you have a 2 simple classes like this:</p>
<p><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="259" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/12/image.png" width="344" border="0" /> </p>
<p>Now, in the global.asax’s init (assuming a web application), we can configure NHibernate using Fluent NHibernate like this:</p>
<p><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="185" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/12/image1.png" width="577" border="0" /> </p>
<p>It uses convention over configuration in lots of places, eg the Id property is always used as identity-column if a property with that name exists.   <br />But you could also easily add your own conventions. If you want to have the Id colums to be ArtistId and AlbumId (and any other className + Id), you’d do:</p>
<p><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="56" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/12/image2.png" width="465" border="0" /> </p>
<p>Want to restrict the namespace as well? No problem!</p>
<p><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="68" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/12/image3.png" width="463" border="0" /> </p>
<p>Fantastic! Now, to see what mapping file this code automagically creates for our Artist class, we can run the following code:</p>
<p><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="119" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/12/image4.png" width="300" border="0" /> </p>
<p>which returns an XmlDocument. In this case, the InnerXml of that document looks like this:</p>
<p><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="312" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/12/image5.png" width="552" border="0" /> </p>
<p>Again: fantastic! See how it even generates the one-to-many relation with the correct end-class, because we defined a property IList&lt;Album&gt;!</p>
<p>Running the same code for the Album class gives:</p>
<p><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="246" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/12/image6.png" width="520" border="0" /> </p>
<p>If you want to use Fluent NHibernate the ‘old’ way, you can still add ClassMap&lt;Artist&gt; to your assembly. Hence, you can even mix it with the AutoPersistenceModel! If you have a classmap file, it’ll use that for your class, if it isn’t there it’ll automatically create a mapping for you!</p>
<p>I’m sold! This makes using NHibernate a breeze. You can get up and running with your NHibernate project so much faster now.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/chrisvandesteeg?a=NJ_l7IiGpgk:CtRJLfgbeaM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/chrisvandesteeg?d=yIl2AUoC8zA" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2008/12/02/fluent-nhibernates-autopersistencemodel-i-love-it/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		<feedburner:origLink>http://www.chrisvandesteeg.nl/2008/12/02/fluent-nhibernates-autopersistencemodel-i-love-it/</feedburner:origLink></item>
		<item>
		<title>jQuery ajax with asp.net mvc preview 5</title>
		<link>http://feedproxy.google.com/~r/chrisvandesteeg/~3/nwfBDwyhtIE/</link>
		<comments>http://www.chrisvandesteeg.nl/2008/09/16/jquery-ajax-with-aspnet-mvc-preview-5/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 18:48:57 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/?p=64</guid>
		<description><![CDATA[Quite some had changed between mvc p4 and mvc p5, so it took some time too update my jquery4mvc project to preview 5. Be sure to check out scott&#8217;s post to read all the new stuff. He&#8217;ll be posting on the ajaxhelpers some time soon also.&#160; If you wish to skip the reading and directly [...]]]></description>
				<content:encoded><![CDATA[<p>Quite some had changed between mvc p4 and mvc p5, so it took some time too update my jquery4mvc project to preview 5. Be sure to check out <a href="http://weblogs.asp.net/scottgu/archive/2008/09/02/asp-net-mvc-preview-5-and-form-posting-scenarios.aspx">scott&#8217;s post</a> to read all the new stuff. He&#8217;ll be posting on the ajaxhelpers some time soon also.&#160; If you wish to skip the reading and directly download the stuff: it&#8217;s at <a href="http://www.codeplex.com/jquery4mvc/Release/ProjectReleases.aspx?ReleaseId=17401">codeplex</a>. </p>
<p>The javascript-only package includes 3 javascript files that allow you to use the default Microsoft AjaxHelper. You can just copy those files to your Content folder and include them in your head section, instead of the MicrosoftAjax.js and MicrosoftMvcAjax.js. All ajax extensions work the same as their Microsoft equivalence,&#160; using jQuery instead of MicrosoftAjax. As a little bonus, you&#8217;ll get back and forward button support for your ajax-links.</p>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/09/image.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="92" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/09/image-thumb.png" width="644" border="0" /></a> </p>
<p>That&#8217;s it, go ahead and use the AjaxHelper functions like you&#8217;re used to. Though a few things have changed for the AjaxHelpers in preview 5, you could still use the introduction <a href="http://www.hanselman.com/blog/ASPNETMVCPreview4UsingAjaxAndAjaxForm.aspx">ASP.NET MVC Preview 4 &#8211; Using Ajax and Ajax.Form</a> by Scott Hanselman if you haven&#8217;t already checked out the AjaxHelper. Main thing that has changed is that you cannot use inline javascript in the AjaxOptions in preview 5, you should now specify a method name. You could also download the entire jQueryMvc project, it holds a sample website showing some of the ajax magic.</p>
<p>Talking about the entire project, it&#8217;s more than just the .js files! The intention of the project is to get you up and running very quickly when you want to create an mvc based ajax application. We use <a href="http://codeplex.com/unity">Unity</a> as our default IoC container.</p>
<p>I think it&#8217;s quite hard to explain exactly what the project does for you, it&#8217;s best really to just look at the sample website, but I will give a brief overview. First, we have a DefaultViewViewEngine. If you mark your controller with a [DefaultView] attribute like so:</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="55" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/09/image1.png" width="406" border="0" /> </p>
<p>If you call in example /Home/Index, by default the Index view will be searched for. If it isn&#8217;t found, the DefaultViewViewEngine will look for a template with the name specified (&quot;default&quot; in the above example). It doesn&#8217;t matter what viewengine you use for your views, it will work for all of them. So what can this do? Look at the structure of the views in the sample site:</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="261" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/09/image2.png" width="189" border="0" /> </p>
<p>As you can see, most of the the views only have an ascx file prefixed with an underscore. Since the views are not found when the actions Home/About, Home/SayHello, Home/Index are called upon, the DefaultViewViewEngine will open Shared/Default.aspx.    <br />This default page does not do much<img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="76" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/09/image3.png" width="879" border="0" /> </p>
<p>As you can see, it just uses the masterpage. But with only little imagination, you can see that you can easily create different default-pages for each controller. The masterpage however, does hold some extra magic:</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="55" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/09/image4.png" width="506" border="0" /></p>
<p>This special contentplaceholder, by default works like a normal placeholder. But, if it doesn&#8217;t get new content from it&#8217;s page, it will ask the ViewEngine(s) to open the view of the current action prefixed with an underscore. So, if you call Home/About, this will ask for Home/_About.&#160; <br />Can you see the magic? For all similar pages, you just have to create the ascx files (or other partials if you use a different viewengine). Those partial views will be pushed into the main page.</p>
<p>But wait, there&#8217;s more! If you make an ajax-request to a controller that has the [AjaxController] attribute, it will return only the partial view! Now, isn&#8217;t that great ? That looks a lot like the updatepanel to me <img src='http://www.chrisvandesteeg.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://www.codeplex.com/jquery4mvc/Release/ProjectReleases.aspx?ReleaseId=17401">Go to codeplex and download the project to see the ajax-magic I&#8217;m so excited about!</a>    <br />Source can be downloaded at Google code: <a href="http://code.google.com/p/jquerymvc/source/checkout">http://code.google.com/p/jquerymvc/source/checkout</a>    <br />The sample website can be seen in action at: <a title="http://www.chrisvandesteeg.nl/demo/jquerymvc5/" href="http://www.chrisvandesteeg.nl/demo/jquerymvc5/">http://www.chrisvandesteeg.nl/demo/jquerymvc5/</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/chrisvandesteeg?a=nwfBDwyhtIE:JzkeUEij9XQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/chrisvandesteeg?d=yIl2AUoC8zA" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2008/09/16/jquery-ajax-with-aspnet-mvc-preview-5/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<feedburner:origLink>http://www.chrisvandesteeg.nl/2008/09/16/jquery-ajax-with-aspnet-mvc-preview-5/</feedburner:origLink></item>
		<item>
		<title>Howto use jQuery with asp.net mvc preview 4′s AjaxHelper</title>
		<link>http://feedproxy.google.com/~r/chrisvandesteeg/~3/UnbV8FRLrXU/</link>
		<comments>http://www.chrisvandesteeg.nl/2008/07/21/howto-use-jquery-with-aspnet-mvc-preview-4s-ajaxhelper/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 20:56:11 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/2008/07/21/howto-use-jquery-with-aspnet-mvc-preview-4s-ajaxhelper/</guid>
		<description><![CDATA[Working on jQuery4mvc preview 4, one of the first things I ofcourse wanted to do was to replace the ASP.NET Ajax library that&#8217;s used by the AjaxHelper. Unfortunately the AjaxHelper itself is sealed, so atm we can&#8217;t (easily) change how the AjaxHelper generates its links. So, as an alternative, I created a javascript library that [...]]]></description>
				<content:encoded><![CDATA[<p>Working on jQuery4mvc preview 4, one of the first things I ofcourse wanted to do was to replace the ASP.NET Ajax library that&#8217;s used by the AjaxHelper.</p>
<p>Unfortunately the AjaxHelper itself is sealed, so atm we can&#8217;t (easily) change how the AjaxHelper generates its links. So, as an alternative, I created a javascript library that uses the same methodnames as the MicrosoftMvcAjax version.</p>
<p>Though at first I was upset that AjaxHelper wasn&#8217;t opened up, this javascript-only solution makes it very easy to use. All you have to do is </p>
<ul>
<li>place the <a href="http://jquery.com/">latest jQuery version</a> in your Content folder; </li>
<li>place <a href="http://www.codeplex.com/jquery4mvc/Release/ProjectReleases.aspx?ReleaseId=15521">my javascript file</a> in your Content folder; </li>
<li>add references in your views (or masterpage ofcourse) to these 2 files instead of referencing the MicrosoftMvcAjax.js and MicrosoftAjax.js file.</li>
</ul>
<p>If you haven&#8217;t played with the AjaxHelper yet, take a look at <a href="http://www.hanselman.com/blog/ASPNETMVCPreview4UsingAjaxAndAjaxForm.aspx">Scott Hanselman&#8217;s post on Using Ajax and Ajax.Form</a></p>
<p>This jQuery version also has a little extra: browser-history support for your ajax requests</p>
<p>Now, go <a href="http://www.codeplex.com/jquery4mvc/Release/ProjectReleases.aspx?ReleaseId=15521">download</a> the js file and play!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/chrisvandesteeg?a=UnbV8FRLrXU:spZ08lkylEM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/chrisvandesteeg?d=yIl2AUoC8zA" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2008/07/21/howto-use-jquery-with-aspnet-mvc-preview-4s-ajaxhelper/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://www.chrisvandesteeg.nl/2008/07/21/howto-use-jquery-with-aspnet-mvc-preview-4s-ajaxhelper/</feedburner:origLink></item>
	</channel>
</rss>
