Session less MVC Controller for MVC 2 / RC

LiveJournal Tags: MVC,MVC 2,session Why a session less controller? Update 5 Feb 2010 – The latest MVC 2 futures on CodePlex contains the the RenderAction() fix – this sample is no longer needed for a session less controller. Use the futures version. You have a single client making multiple concurrent requests to the server. The…


Using the BeginMethod/EndMethod pattern with MVC

If your asynchronous action method calls a service which exposes methods using theBeginMethod() / EndMethod() pattern , your callback will be executed on a thread which is not under thecontrol of ASP.NET. Some consequences of this are that HttpContext.Current will be null, andthere will be race conditions accessing members like AsyncManager.Parameters. To restoreHttpContext.Current and eliminate…


Should my database calls be Asynchronous?

Update 28 November 2012: The combination of await, async, and the Task object makes it much easier for you to write asynchronous code in .NET 4.5.  Now that EF 6 is supporting Async Query and Save, you should take advantage of asynchronous programming. (As of this update, EF6 is not released so don’t use it…


Tips on getting your ASP.NET MVC questions answered quickly

When you run into an issue or have a question about ASP.NET MVC the best place for it is the MVC Forum.  When you write your question, there are a few simple things that you can do to make it easier for the ‘experts’ to answer (and hence to get an answer quicker!). 1. Try…


MVC FAQ

Please post corrections/submissions to the MVC Forum. Include MVC FAQ in the title. MSDN articles with Full project samples (vb and c#) (MVC 2) MVC Best Practices Kazi Manzur Rashid’s MVC Best Practices  (great 2 part series) Performance Security Post LINQ to SQL To SQL Questions here  Post Entity Framework Questions here Q: Should I…


Client Side Validation for MVC 2 P2

MVC 2 Preview 1 added support for DataAnnotations. In my MSDN article How to: Validate Model Data Using DataAnnotations Attributes I covered the basics of validation. Preview 2 adds client validation with the addition of one line of code. The following class contains the model I use in my sample download. public class Pals {…


DRY-ing out the MVC 2 Templated Helpers

In my MSDN article  Using Templated Helpers to Display Data, I show how they provide a very productive means of building a UI for data sets. The code below shows a typical use of the Display and Label helpers.<span style=”font-weight:bold;“> <%= Html.Label(“Name”) %> :</span> <%= Html.Display(“Name”) %> <br/><span style=”font-weight:bold;“> <%= Html.LabelFor(Pals => Pals.ID)%> :</span> <%=…


Using DataAnnotations in MVC 2 – Catching up to Dynamic Data

  DataAnnotations help you write robust validation and prevent the type of annoying error message shown above. Form submittal failure when a field doesn’t validate can be very frustrating –  especially when there is no indication of the problematic property or the constraint violation. I happened to get the Outlook error above when I attempted…


New Templated Helpers Improve SoC

  SoC (from WikiPedia)In my MSDN article Walkthrough: Using Templated Helpers to Display Data I show how to annotate your data model to specify that a field should be rendered with a type-specific control.  The download sample code also includes a control using the new Html.EditorFor helper. With one line of code you can open…


Setting font attributes with UIHint in your Entity Partial Class

  I’ve written a simple Field Template ( RedBold.ascx ) that reads most font attributes and applies them to your field values. The new entity templates make it easy to apply font attributes to the field labels. The image below shows several font attributes applied to the partial class for the Customer table of the…