LINQ to SQL - Return Scalar Value from a Stored Procedure

One of the best things about LINQ to SQL is that is really does have solid support for stored procedures.  However, it's not quite as friendly as dynamic LINQ to SQL with scalar values because you can't take advantage of anonymous types.  Instead you must return an actual known type.  Furthermore, this can't be a primitive so you can't return string or bool directly.  You also can't use a class that doesn't have a default (parameterless) constructor so that also rules out nullable types like Nu...


MVC ComponentController vs. ViewUserControl

UPDATE: The component controller was removed from the MVC framework before the RTM release. For an updated version of this post, click **here [http://geekswithblogs.net/michelotti/archive/2009/07/15/mvc-widgets-with-renderaction.aspx] .** At some point when creating a web app, you're going to want some reusable UI components.  This might be because you want the same visual UI snippet repeated more than once on a single page or it might be because you want to use the same component on multiple p...


MVC JSON - JsonResult and jQuery

The latest release of the MVC framework provides the JsonResult for Controller actions.  I was surprised that I did not find a weatlh of examples for usage so I figured it shouldn't be too hard to get a decent example going.  It turns out, it was even easier than I anticipated.  I wanted to create an example where I would invoke an AJAX call to dynamically populate a dropdown list. jQuery [http://jquery.com/]has recently received a huge surge of interest of the ASP.NET MVC community so I've bee...


MVC Control Extensions - Automatically Set Control Names

To set a normal text box in the MVC framework, the most typical code would look like this: The key here is that you should set the name of the textbox to be the exact same name of the property name.  If you do this, then it enables you to use extension methods such as the UpdateFrom() method to automatically populate your object from Request.Form parameters when you post to your controller action.  This is all well and good but it is very easy to make a typo when typing the "FirstName" stri...


Leverage EntLib Validation Application Block in MVC

UPDATE: This post is now out of date as of the CTP5 release of the MVC framework. For the lastest version, see this post here [http://geekswithblogs.net/michelotti/archive/2008/10/04/enterprise-library-validation-application-block-with-asp.net-mvc.aspx] . One of the areas of MVC that is still an open area in development is how best to handle UI validations.  There are numerous approaches currently being examined. The Enterprise Library's VAB is great because it allows you to specify all your v...