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

<channel>
	<title>Martijn Boland &#187; ASP.NET MVC</title>
	<atom:link href="http://blogs.taiga.nl/martijn/tag/aspnet-mvc/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.taiga.nl/martijn</link>
	<description>New adventures in .NET</description>
	<lastBuildDate>Wed, 25 Jan 2012 22:27:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Introducing Actya &#8211; a .NET CMS that doesn&#8217;t get in your way</title>
		<link>http://blogs.taiga.nl/martijn/2012/01/23/introducing-actya/</link>
		<comments>http://blogs.taiga.nl/martijn/2012/01/23/introducing-actya/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 11:42:00 +0000</pubDate>
		<dc:creator>martijn</dc:creator>
				<category><![CDATA[Actya]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[RavenDB]]></category>

		<guid isPermaLink="false">http://blogs.taiga.nl/martijn/?p=227</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2012/01/23/introducing-actya/' addthis:title='Introducing Actya &#8211; a .NET CMS that doesn&#8217;t get in your way '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>Actya is a simple open source ASP.NET MVC Content Management System (CMS). Why on earth would we need another CMS? Quite often, a CMS is chosen as application framework for custom application development because you’ll get a lot for free: navigation, security and content management (obviously). Custom applications are then developed as modules that run <a href="http://blogs.taiga.nl/martijn/2012/01/23/introducing-actya/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2012/01/23/introducing-actya/' addthis:title='Introducing Actya &#8211; a .NET CMS that doesn&#8217;t get in your way '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p><a href="http://actya.codeplex.com">Actya</a> is a simple open source ASP.NET MVC Content Management System (CMS).</p>
<h2>Why on earth would we need another CMS?</h2>
<p>Quite often, a CMS is chosen as application framework for custom application development because you’ll get a lot for free: navigation, security and content management (obviously). Custom applications are then developed as modules that run within the context of the CMS. <a href="http://cuyahoga-project.org">Cuyahoga</a>, the CMS I’ve started  8 years ago works exactly like this.</p>
<p>Rob Conery <a href="http://wekeroad.com/2011/12/06/nuget-and-orchard/">describes an issue with this solution</a>:</p>
<blockquote><p>I’ve deployed Big CMS’s before as a solution for clients and every single time we decided to move away. They’re great for getting off the ground – but after a while there’s jus too much friction.</p></blockquote>
<p>And that’s probably what many of us experience: a CMS gets in the way when your main focus is the custom application. This is the single main reason to create Actya: <strong>a CMS that doesn’t get in your way when doing custom development.</strong></p>
<h2><span style="color: #111111;">CMS as add-on</span></h2>
<p>Actya can act as an add-on library for your application. While developing your custom application in Visual Studio, you can add it with <a href="http://nuget.org/packages/actya">NuGet</a> just like any other library. The first time you run your application after adding Actya, an installer kicks in to ask you where you want to have your CMS data stored, what theme you want to use and which account is the CMS administrator. No further configuration required <strong>and nothing has to change in your custom application.</strong></p>
<p>The video below shows this scenario with <a href="https://github.com/nuget/nugetgallery">NuGetGallery</a> as the ‘custom’ application:</p>
<div id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:336ff211-5b84-4b16-a7bf-1637ab8400da" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<div><object width="448" height="252" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.youtube.com/v/AnwwcO26zuU?hl=en&amp;hd=1" /><embed width="448" height="252" type="application/x-shockwave-flash" src="http://www.youtube.com/v/AnwwcO26zuU?hl=en&amp;hd=1" /></object></div>
</div>
<p>Even though Actya is mainly designed to act as an add-on CMS, you can also use it as a simple regular CMS. Download it at from <a href="http://actya.codeplex.com/releases/">CodePlex downloads page</a>, point an IIS 7+ web site or application to the extracted files, open de site in your browser and the installation starts automatically.</p>
<p>After installation, you can access Actya’s admin pages at <a href="http://my-host-or-application/cmsadmin">http://<em>my-host-or-application</em>/<strong>cmsadmin</strong>.</a></p>
<h2>RavenDB document database</h2>
<p>Here’s the other reason for creating Actya: schema-less <a href="http://en.wikipedia.org/wiki/NoSQL">NoSQL</a> databases are considered to be ideal for CMS applications because you can put any type of content in it without having to alter a database schema or have some kind of monstrous <a href="http://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80%93value_model">Entity-Attribute-Value</a> model. I wanted to experience if that claim is true.</p>
<p>Actya uses the .NET NoSQL database <a href="http://ravendb.net">RavenDB</a> and it really makes development easier. Not only due to the flexibility of the schema-less design but also to the absence of a mapping layer. Wonderful! A cool feature of RavenDB is the embedded mode where you don’t need a database server at all. Actya uses this mode by default (the data goes in App_Data), but can also connect to an existing RavenDB server.</p>
<h2></h2>
<h2></h2>
<h2>Requirements</h2>
<ul>
<li><span style="color: #111111;">ASP.NET 4.0</span></li>
<li><span style="color: #111111;">Full-Trust environment</span></li>
</ul>
<h2>Wanted: Feedback</h2>
<p>I’ve released the first alpha version to see if anybody finds this CMS useful. Your feedback will have a have a lot of weight in determining future development. If you have any, please go to <a href="http://actya.codeplex.com/discussions">http://actya.codeplex.com/discussions</a> and open a discussion with ‘User Feedback’ as topic.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.taiga.nl/martijn/2012/01/23/introducing-actya/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>MvcPaging 1.0.2</title>
		<link>http://blogs.taiga.nl/martijn/2011/12/07/mvcpaging-1-0-2/</link>
		<comments>http://blogs.taiga.nl/martijn/2011/12/07/mvcpaging-1-0-2/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 21:57:46 +0000</pubDate>
		<dc:creator>martijn</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[Paging]]></category>
		<category><![CDATA[Razor]]></category>

		<guid isPermaLink="false">http://blogs.taiga.nl/martijn/2011/12/07/mvcpaging-1-0-2/</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/12/07/mvcpaging-1-0-2/' addthis:title='MvcPaging 1.0.2 '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>A new version of the MvcPaging component is available via NuGet with the following changes: Added ItemStart and ItemEnd properties to IPagedList (Displaying items {ItemStart} &#8211; {ItemEnd}). Non-canonical url&#8217;s for page 1 (https://github.com/martijnboland/MvcPaging/issues/2). So the core library hasn’t changed much, and in all honesty, I think it’s pretty much done. Please leave a reply if <a href="http://blogs.taiga.nl/martijn/2011/12/07/mvcpaging-1-0-2/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/12/07/mvcpaging-1-0-2/' addthis:title='MvcPaging 1.0.2 '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>A new version of the <a href="https://github.com/martijnboland/mvcpaging">MvcPaging</a> component is available via <a href="https://nuget.org/packages/MvcPaging">NuGet</a> with the following changes:</p>
<ul>
<li>Added ItemStart and ItemEnd properties to IPagedList (Displaying items {ItemStart} &#8211; {ItemEnd}). </li>
<li>Non-canonical url&#8217;s for page 1 (<a href="https://github.com/martijnboland/MvcPaging/issues/2">https://github.com/martijnboland/MvcPaging/issues/2</a>).</li>
</ul>
<p>So the core library hasn’t changed much, and in all honesty, I think it’s pretty much done. Please leave a reply if you think otherwise.</p>
<p>What did change substantially is the sample application. It was still very much ASP.NET 1.0 with WebForms views. This is now a proper ASP.NET MVC 3 application with Razor views and the default ASP.NET MVC 4.0 template for look &amp; feel.</p>
<p>&#160;<a href="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/12/Screenshot.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="Screenshot" border="0" alt="Screenshot" src="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/12/Screenshot_thumb.png" width="640" height="400" /></a></p>
<p>The sample application can be found at <a href="https://github.com/martijnboland/mvcpaging">GitHub</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.taiga.nl/martijn/2011/12/07/mvcpaging-1-0-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Model Binders and Request Validation</title>
		<link>http://blogs.taiga.nl/martijn/2011/09/29/custom-model-binders-and-request-validation/</link>
		<comments>http://blogs.taiga.nl/martijn/2011/09/29/custom-model-binders-and-request-validation/#comments</comments>
		<pubDate>Thu, 29 Sep 2011 11:15:21 +0000</pubDate>
		<dc:creator>martijn</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://blogs.taiga.nl/martijn/2011/09/29/custom-model-binders-and-request-validation/</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/09/29/custom-model-binders-and-request-validation/' addthis:title='Custom Model Binders and Request Validation '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>In ASP.NET MVC you can create your own model binders to control the way that models are constructed from an HTTP request. For example, if you don’t want any whitespace characters in your model, you can create a custom model binder that trims all whitespace characters when constructing&#160; a model object. You only have to <a href="http://blogs.taiga.nl/martijn/2011/09/29/custom-model-binders-and-request-validation/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/09/29/custom-model-binders-and-request-validation/' addthis:title='Custom Model Binders and Request Validation '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>In ASP.NET MVC you can create your own model binders to control the way that models are constructed from an HTTP request. For example, if you don’t want any whitespace characters in your model, you can create a custom model binder that trims all whitespace characters when constructing&#160; a model object. You only have to implement the <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.imodelbinder.aspx">IModelBinder</a> interface and its BindModel method in a class and register it during application startup.</p>
<h3>Getting the value from the HTTP request</h3>
<p>There are many examples online of how to build a custom model binder. In all these examples you can find a common way of getting a value from the HTTP request:</p>
<pre class="brush: csharp;">public class MyModelBinder: IModelBinder
{
    public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        var valueProviderResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
        if (valueProviderResult != null)
        {
            var theValue = valueProviderResult.AttemptedValue;

            // etc...
        }
    }
}</pre>
<p>The code above works nicely and you get protection for potential dangerous request values out of the box. Now let’s assume that we <em>want </em>some potential dangerous values like HTML or XML tags in our model. The recommended way is to add an [AllowHtml] attribute to the model property that may contain HTML and no validation happens for that property. Alternatively, it’s possible to add an [ValidateInput(false)] attribute to the controller action that accepts the model with HTML content, but this turns off validation for<em> </em>all model properties. </p>
<h3>A potentially dangerous Request.Form value was detected from the client</h3>
<p>Wait a minute! Didn’t we just explicitly say to allow those dangerous values? What’s happening?</p>
<p>It appears that a call to bindingContext.ValueProvider.GetValue() in the code above <em>always</em> validates the data, regardless any attributes. Digging into the ASP.NET MVC sources revealed that the DefaultModelBinder first checks&#160; if request validation is required and then calls the bindingContext.UnvalidatedValueProvider.GetValue() method with a parameter that indicates if validation is required or not. </p>
<p>Unfortunately we can’t use any of the framework code because it’s sealed, private or whatever to protect ignorant devs from doing dangerous stuff, but&#160; it’s not too difficult to create a working custom model binder that respects the AllowHtml and ValidateInput attributes:</p>
<pre class="brush: csharp;">public class MyModelBinder: IModelBinder
{
    public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        // First check if request validation is required
        var shouldPerformRequestValidation = controllerContext.Controller.ValidateRequest &amp;&amp; bindingContext.ModelMetadata.RequestValidationEnabled;

        // Get value
        var valueProviderResult = bindingContext.GetValueFromValueProvider(shouldPerformRequestValidation);
        if (valueProviderResult != null)
        {
            var theValue = valueProviderResult.AttemptedValue;

            // etc...
        }
    }
}</pre>
<p>The other required piece is a way to retrieve an unvalidated value. In this example we use an extension method for the ModelBindingContext class:</p>
<pre class="brush: csharp;">public static ValueProviderResult GetValueFromValueProvider(this ModelBindingContext bindingContext, bool performRequestValidation)
{
    var unvalidatedValueProvider = bindingContext.ValueProvider as IUnvalidatedValueProvider;
    return (unvalidatedValueProvider != null)
               ? unvalidatedValueProvider.GetValue(bindingContext.ModelName, !performRequestValidation)
               : bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://blogs.taiga.nl/martijn/2011/09/29/custom-model-binders-and-request-validation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>NuGet package for MVC pager</title>
		<link>http://blogs.taiga.nl/martijn/2011/05/12/nuget-package-for-mvc-pager/</link>
		<comments>http://blogs.taiga.nl/martijn/2011/05/12/nuget-package-for-mvc-pager/#comments</comments>
		<pubDate>Thu, 12 May 2011 15:15:35 +0000</pubDate>
		<dc:creator>martijn</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[NuGet]]></category>
		<category><![CDATA[Paging]]></category>

		<guid isPermaLink="false">http://blogs.taiga.nl/martijn/2011/05/12/nuget-package-for-mvc-pager/</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/05/12/nuget-package-for-mvc-pager/' addthis:title='NuGet package for MVC pager '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>It’s now possible to add the MVC pager to your own project with NuGet. Or from Visual Studio with ‘Manage NuGet Packages&#8230;’ and then search for ‘MvcPaging’. After installing, you can immediately use the Pager HtmlHelper in your views: et voilà! We also have include the IPagedList for your convenience: For more info, check out <a href="http://blogs.taiga.nl/martijn/2011/05/12/nuget-package-for-mvc-pager/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/05/12/nuget-package-for-mvc-pager/' addthis:title='NuGet package for MVC pager '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>It’s now possible to add the <a href="https://github.com/martijnboland/MvcPaging">MVC pager</a> to your own project with <a href="http://nuget.org/">NuGet</a>.</p>
<p><a href="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/image4.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/image_thumb4.png" alt="image" width="600" height="77" border="0" /></a></p>
<p>Or from Visual Studio with ‘Manage NuGet Packages&#8230;’ and then search for ‘MvcPaging’.</p>
<p>After installing, you can immediately use the Pager HtmlHelper in your views:</p>
<p><a href="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/image5.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/image_thumb5.png" alt="image" width="600" height="187" border="0" /></a></p>
<p>et voilà!</p>
<p><a href="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/image6.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/image_thumb6.png" alt="image" width="600" height="392" border="0" /></a></p>
<p>We also have include the IPagedList for your convenience:</p>
<p><a href="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/image7.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/image_thumb7.png" alt="image" width="600" height="331" border="0" /></a></p>
<p>For more info, check out <a href="http://blogs.taiga.nl/martijn/2008/08/27/paging-with-aspnet-mvc/">the original blogpost</a> that started it or the <a href="https://github.com/martijnboland/MvcPaging">github project page</a>.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.taiga.nl/martijn/2011/05/12/nuget-package-for-mvc-pager/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Keep your users informed with ASP.NET MVC</title>
		<link>http://blogs.taiga.nl/martijn/2011/05/03/keep-your-users-informed-with-asp-net-mvc/</link>
		<comments>http://blogs.taiga.nl/martijn/2011/05/03/keep-your-users-informed-with-asp-net-mvc/#comments</comments>
		<pubDate>Tue, 03 May 2011 14:09:50 +0000</pubDate>
		<dc:creator>martijn</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[Notification]]></category>

		<guid isPermaLink="false">http://blogs.taiga.nl/martijn/?p=161</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/05/03/keep-your-users-informed-with-asp-net-mvc/' addthis:title='Keep your users informed with ASP.NET MVC '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>In almost every application, feedback from the application to the user via notification messages is required. For some strange reason, we don’t have a standard way in .NET web applications for dealing with this kind of messages and I find myself hacking some half-baked solutions over and over again. Starting from today, this must end! <a href="http://blogs.taiga.nl/martijn/2011/05/03/keep-your-users-informed-with-asp-net-mvc/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/05/03/keep-your-users-informed-with-asp-net-mvc/' addthis:title='Keep your users informed with ASP.NET MVC '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>In almost every application, feedback from the application to the user via notification messages is required. </p>
<p><a href="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/success.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="success" border="0" alt="success" src="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/success_thumb.png" width="513" height="52" /></a></p>
<p>For some strange reason, we don’t have a standard way in .NET web applications for dealing with this kind of messages and I find myself hacking some half-baked solutions over and over again. Starting from today, this must end! In this post we’re going to find a solution for ASP.NET MVC 3.</p>
<h3>One single way to display messages</h3>
<p>This is the one and only requirement: </p>
<blockquote><p>In every scenario I want to be able to call ShowMessage() from my controller action and the message appears on the screen.</p>
</blockquote>
<h3>ShowMessage extension method</h3>
<p>To have a ShowMessage method in every controller action, we could implement it in a base controller class or create an extension method. Let’s try an extension method:</p>
<pre class="brush: csharp;">public static void ShowMessage(this Controller controller, MessageType messageType, string message, bool showAfterRedirect = false)
{
    var messageTypeKey = messageType.ToString();
    if (showAfterRedirect)
    {
        controller.TempData[messageTypeKey] = message;
    }
    else
    {
        controller.ViewData[messageTypeKey] = message;
    }
}</pre>
<p>All this method does is take a message type enum (Success, Warning or Error) and a message and store it in either ViewData or TempData, depending on the flag ‘showAfterRedirect’. TempData is for <a href="http://en.wikipedia.org/wiki/Post/Redirect/Get">Post-Redirect-Get</a> situations.</p>
<p>We can now call ShowMessage(). With this solution it’s only possible to store one type of message per request, but that should be enough (even more than one message is already troublesome).</p>
<h3>RenderMessages HTML Helper</h3>
<p>Creating messages is one thing, but what about displaying them? It’s also easy. Enter the RenderMessages() HTML helper:</p>
<pre class="brush: csharp;">/// &lt;summary&gt;
/// Render all messages that have been set during execution of the controller action.
/// &lt;/summary&gt;
/// &lt;param name=&quot;htmlHelper&quot;&gt;&lt;/param&gt;
/// &lt;returns&gt;&lt;/returns&gt;
public static HtmlString RenderMessages(this HtmlHelper htmlHelper)
{
    var messages = String.Empty;
    foreach (var messageType in Enum.GetNames(typeof(MessageType)))
    {
        var message = htmlHelper.ViewContext.ViewData.ContainsKey(messageType)
                        ? htmlHelper.ViewContext.ViewData[messageType]
                        : htmlHelper.ViewContext.TempData.ContainsKey(messageType)
                            ? htmlHelper.ViewContext.TempData[messageType]
                            : null;
        if (message != null)
        {
            var messageBoxBuilder = new TagBuilder(&quot;div&quot;);
            messageBoxBuilder.AddCssClass(String.Format(&quot;messagebox {0}&quot;, messageType.ToLowerInvariant()));
            messageBoxBuilder.SetInnerText(message.ToString());
            messages += messageBoxBuilder.ToString();
        }
    }
    return MvcHtmlString.Create(messages);
}</pre>
<p>It iterates through all possible message types, tries to find a message in either ViewData or TempData and creates a div with the message in it.<br />
  <br />Put the helper in the Layout page, add some css classes (.messagebox, .succes, .warning and .error) and we’re all set.</p>
<h3>What about AJAX?</h3>
<p>Now this is getting tricky. In our AJAX actions, we can still call ShowMessage(), but how should the message be displayed if we only return some JSON data or a partial view? One solution would be to wrap all AJAX results in a special JSON view result with the notification messages and the original result embedded. Drawback is that we have quite some work to do on the client-side to handle all this.</p>
<h3>HTTP headers to the rescue</h3>
<p>I discovered a very nice solution on StackOverflow: <a href="http://stackoverflow.com/questions/366311/how-do-you-handle-rails-flash-with-ajax-requests">use custom HTTP headers to store a message</a>. With the help of a global action filter we can check if there are messages in the ViewData dictionary and when the request was an AJAX request, copy the messages to a custom HTTP header.</p>
<pre class="brush: csharp;">/// &lt;summary&gt;
/// If we're dealing with ajax requests, any message that is in the view data goes to
/// the http header.
/// &lt;/summary&gt;
public class AjaxMessagesFilter : ActionFilterAttribute
{
    public override void OnActionExecuted(ActionExecutedContext filterContext)
    {
        if (filterContext.HttpContext.Request.IsAjaxRequest())
        {
            var viewData = filterContext.Controller.ViewData;
            var response = filterContext.HttpContext.Response;

            foreach (var messageType in Enum.GetNames(typeof(MessageType)))
            {
                var message = viewData.ContainsKey(messageType)
                                ? viewData[messageType]
                                : null;
                if (message != null) // We store only one message in the http header. First message that comes wins.
                {
                    response.AddHeader(&quot;X-Message-Type&quot;, messageType);
                    response.AddHeader(&quot;X-Message&quot;, message.ToString());
                    return;
                }
            }
        }
    }
}</pre>
<p><a href="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/x-message.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="x-message" border="0" alt="x-message" src="http://blogs.taiga.nl/martijn/wp-content/uploads/2011/05/x-message_thumb.png" width="704" height="304" /></a></p>
<p>Finally the message in the HTTP headers are displayed with a little bit of jQuery:</p>
<pre class="brush: js;">$(document).ready(function () {
    handleAjaxMessages();
});

function handleAjaxMessages() {
    $(document).ajaxSuccess(function (event, request) {
        checkAndHandleMessageFromHeader(request);
    }).ajaxError(function (event, request) {
        displayMessage(request.responseText, &quot;error&quot;);
    });
}

function checkAndHandleMessageFromHeader(request) {
    var msg = request.getResponseHeader('X-Message');
    if (msg) {
        displayMessage(msg, request.getResponseHeader('X-Message-Type'));
    }
}

function displayMessage(message, messageType) {
    $(&quot;#messagewrapper&quot;).html('&lt;div class=&quot;messagebox ' + messageType.toLowerCase() + '&quot;&gt;&lt;/div&gt;');
    $(&quot;#messagewrapper .messagebox&quot;).text(message);
}</pre>
<h3>Demo</h3>
<p>For a closer look <a href="http://demo.taiga.nl/notification/" target="_blank">check out the live demo</a> or download the VS2010 solution from <a href="https://github.com/martijnboland/MvcNotification">GitHub</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.taiga.nl/martijn/2011/05/03/keep-your-users-informed-with-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>MVC Pager update: now with AJAX support</title>
		<link>http://blogs.taiga.nl/martijn/2011/03/23/mvc-pager-update-now-with-ajax-support/</link>
		<comments>http://blogs.taiga.nl/martijn/2011/03/23/mvc-pager-update-now-with-ajax-support/#comments</comments>
		<pubDate>Wed, 23 Mar 2011 13:26:59 +0000</pubDate>
		<dc:creator>martijn</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Paging]]></category>

		<guid isPermaLink="false">http://blogs.taiga.nl/martijn/2011/03/23/mvc-pager-update-now-with-ajax-support/</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/03/23/mvc-pager-update-now-with-ajax-support/' addthis:title='MVC Pager update: now with AJAX support '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>The MVC pager now has support for AJAX scenario’s, thanks to Bart Lenaerts. This was my first GitHub pull request and everything went pretty smoothly. Check out the demo application for an example. Visit the GitHub project page to download the solution.]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/03/23/mvc-pager-update-now-with-ajax-support/' addthis:title='MVC Pager update: now with AJAX support '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>The <a href="http://blogs.taiga.nl/martijn/2008/08/27/paging-with-aspnet-mvc/">MVC pager</a> now has support for AJAX scenario’s, thanks to <a href="https://github.com/blenaerts">Bart Lenaerts</a>. This was my first <a href="https://github.com">GitHub</a> pull request and everything went pretty smoothly.</p>
<p>Check out the demo application for an example. Visit the <a href="https://github.com/martijnboland/MvcPaging">GitHub project</a> page to download the solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.taiga.nl/martijn/2011/03/23/mvc-pager-update-now-with-ajax-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MVC Pager update</title>
		<link>http://blogs.taiga.nl/martijn/2011/02/11/mvc-pager-update/</link>
		<comments>http://blogs.taiga.nl/martijn/2011/02/11/mvc-pager-update/#comments</comments>
		<pubDate>Fri, 11 Feb 2011 12:16:19 +0000</pubDate>
		<dc:creator>martijn</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Paging]]></category>

		<guid isPermaLink="false">http://blogs.taiga.nl/martijn/2011/02/11/mvc-pager-update/</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/02/11/mvc-pager-update/' addthis:title='MVC Pager update '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>Just a short message to let you know that the MVC Pager demo is upgraded to ASP.NET MVC3 and VS 2010. Get it at https://github.com/martijnboland/MvcPaging.]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2011/02/11/mvc-pager-update/' addthis:title='MVC Pager update '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>Just a short message to let you know that the <a href="http://blogs.taiga.nl/martijn/2008/08/27/paging-with-aspnet-mvc/">MVC Pager demo</a> is upgraded to ASP.NET MVC3 and VS 2010. Get it at <a title="https://github.com/martijnboland/MvcPaging" href="https://github.com/martijnboland/MvcPaging">https://github.com/martijnboland/MvcPaging</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.taiga.nl/martijn/2011/02/11/mvc-pager-update/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Raven DB ASP.NET Membership Provider</title>
		<link>http://blogs.taiga.nl/martijn/2010/11/25/raven-db-asp-net-membership-provider/</link>
		<comments>http://blogs.taiga.nl/martijn/2010/11/25/raven-db-asp-net-membership-provider/#comments</comments>
		<pubDate>Thu, 25 Nov 2010 13:54:45 +0000</pubDate>
		<dc:creator>martijn</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Membership]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[RavenDB]]></category>

		<guid isPermaLink="false">http://blogs.taiga.nl/martijn/2010/11/25/raven-db-asp-net-membership-provider/</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2010/11/25/raven-db-asp-net-membership-provider/' addthis:title='Raven DB ASP.NET Membership Provider '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>During the last year I’ve been looking at various NoSQL databases. I’m particularly interested in the flexibility (no fixed schema) and I don’t care that much for scalability that some of these databases provide, therefore I focused on document databases like CouchDB, MongoDB and Raven DB. After some reading, I decided it was time for <a href="http://blogs.taiga.nl/martijn/2010/11/25/raven-db-asp-net-membership-provider/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2010/11/25/raven-db-asp-net-membership-provider/' addthis:title='Raven DB ASP.NET Membership Provider '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>During the last year I’ve been looking at various <a href="http://en.wikipedia.org/wiki/NoSQL">NoSQL</a> databases. I’m particularly interested in the flexibility (no fixed schema) and I don’t care that much for scalability that some of these databases provide, therefore I focused on document databases like <a href="http://couchdb.apache.org/">CouchDB</a>, <a href="http://www.mongodb.org/">MongoDB</a> and <a href="http://ravendb.net/">Raven DB</a>.</p>
<p>After some reading, I decided it was time for an experiment and took Raven DB to create an ASP.NET membership provider. The main reason I chose Raven DB is that you can run it embedded in your .NET application (for example in ~/App_Data) without a separate server and it’s even possible to run the entire database in-memory, which is ideal for tests.</p>
<p>The result of the experiment can be found at <a title="https://github.com/martijnboland/RavenDBMembership" href="https://github.com/martijnboland/RavenDBMembership">https://github.com/martijnboland/RavenDBMembership</a>. It’s a VS 2010 solution with the membership provider, some integration tests and an ASP.NET MVC 3 sample app. You can also directly <a href="https://github.com/martijnboland/RavenDBMembership/zipball/master">download it from here</a>.</p>
<p><em>Disclaimer:</em></p>
<p><em>I’m not sure that creating a Membership provider was the right thing to do to experience NoSQL. Sure, the provider works, but the Membership API forces you into a direction that isn’t necessarily suitable for document databases and there might be some NoSQL anti-patterns here and there in the code</em></p>
<p><em>Oh, and the ASP.NET MVC sample app extends the Membership mess that comes with the default MVC project template. Don’t take this as some best practices example.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.taiga.nl/martijn/2010/11/25/raven-db-asp-net-membership-provider/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Entity Framework 4 Code-First demo updated to Feature CTP3</title>
		<link>http://blogs.taiga.nl/martijn/2010/04/27/entity-framework-4-code-first-demo-updated-to-feature-ctp3/</link>
		<comments>http://blogs.taiga.nl/martijn/2010/04/27/entity-framework-4-code-first-demo-updated-to-feature-ctp3/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 20:51:13 +0000</pubDate>
		<dc:creator>martijn</dc:creator>
				<category><![CDATA[O/R mapping]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Demo]]></category>
		<category><![CDATA[Entity Framework]]></category>

		<guid isPermaLink="false">http://blogs.taiga.nl/martijn/2010/04/27/entity-framework-4-code-first-demo-updated-to-feature-ctp3/</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2010/04/27/entity-framework-4-code-first-demo-updated-to-feature-ctp3/' addthis:title='Entity Framework 4 Code-First demo updated to Feature CTP3 '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>The EF 4 code-first demo has been updated to reference the EF4 Feature CTP3 dll at its default location. To run the demo, you have to make sure that the you have it installed. Download the EF 4 Feature CTP3 at http://www.microsoft.com/downloads/details.aspx?FamilyID=af18e652-9ea7-478b-8b41-8424b94e3f58&#38;displayLang=en. Although the demo was originally developed with VS 2010 Beta 2 everything works <a href="http://blogs.taiga.nl/martijn/2010/04/27/entity-framework-4-code-first-demo-updated-to-feature-ctp3/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2010/04/27/entity-framework-4-code-first-demo-updated-to-feature-ctp3/' addthis:title='Entity Framework 4 Code-First demo updated to Feature CTP3 '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>The <a href="http://blogs.taiga.nl/martijn/2009/11/22/entity-framework-4-0-a-fresh-start-with-demo-application/">EF 4 code-first demo</a> has been updated to reference the EF4 Feature CTP3 dll at its default location. To run the demo, you have to make sure that the you have it installed. Download the EF 4 Feature CTP3 at <a title="http://www.microsoft.com/downloads/details.aspx?FamilyID=af18e652-9ea7-478b-8b41-8424b94e3f58&amp;displayLang=en" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=af18e652-9ea7-478b-8b41-8424b94e3f58&amp;displayLang=en">http://www.microsoft.com/downloads/details.aspx?FamilyID=af18e652-9ea7-478b-8b41-8424b94e3f58&amp;displayLang=en</a>.</p>
<p>Although the demo was originally developed with VS 2010 Beta 2 everything works perfectly fine on VS 2010 RTM.</p>
<p>You can find the demo sources at github: <a title="http://github.com/martijnboland/EF4-codeonly-demo" href="http://github.com/martijnboland/EF4-codeonly-demo">http://github.com/martijnboland/EF4-codeonly-demo</a> where it’s also possible to download the sources all at once.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.taiga.nl/martijn/2010/04/27/entity-framework-4-code-first-demo-updated-to-feature-ctp3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Paging demo for ASP.NET MVC 2</title>
		<link>http://blogs.taiga.nl/martijn/2010/01/27/paging-demo-for-asp-net-mvc-2/</link>
		<comments>http://blogs.taiga.nl/martijn/2010/01/27/paging-demo-for-asp-net-mvc-2/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 18:27:58 +0000</pubDate>
		<dc:creator>martijn</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Area]]></category>
		<category><![CDATA[Paging]]></category>

		<guid isPermaLink="false">http://blogs.taiga.nl/martijn/2010/01/27/paging-demo-for-asp-net-mvc-2/</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2010/01/27/paging-demo-for-asp-net-mvc-2/' addthis:title='Paging demo for ASP.NET MVC 2 '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>During work, I discovered that the pager that I created a while ago didn’t work properly when using ASP.NET MVC2 area’s. The links that were generated didn’t count for the current area that the controller and views were in, resulting in wrong urls. Luckily the ASP.NET MVC team also ran into this issue and created <a href="http://blogs.taiga.nl/martijn/2010/01/27/paging-demo-for-asp-net-mvc-2/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blogs.taiga.nl/martijn/2010/01/27/paging-demo-for-asp-net-mvc-2/' addthis:title='Paging demo for ASP.NET MVC 2 '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>During work, I discovered that the <a href="http://blogs.taiga.nl/martijn/2008/08/27/paging-with-aspnet-mvc/" target="_blank">pager that I created a while ago</a> didn’t work properly when using ASP.NET MVC2 area’s. The links that were generated didn’t count for the current area that the controller and views were in, resulting in wrong urls. Luckily the ASP.NET MVC team also ran into this issue and created an GetVirtualPathForArea() extension method on RouteCollection. Calling this one, instead of GetVirtualPath() made things work properly in area’s.</p>
<p>You can get the code for ASP.NET MVC 2 at <a title="http://github.com/martijnboland/MvcPaging/tree/mvc2" href="http://github.com/martijnboland/MvcPaging/tree/mvc2">http://github.com/martijnboland/MvcPaging/tree/mvc2</a> (mvc2 branch of the MvcPaging repository).</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.taiga.nl/martijn/2010/01/27/paging-demo-for-asp-net-mvc-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

