Posts
All the articles I've posted.
-
CarTrackr - Sample ASP.NET MVC application
Some people may have already noticed the link in my VISUG session blog post, but for those who didn't... I've released my sample application CarTrackr on CodePlex. CarTrackr is a sample application for the ASP.NET MVC framework using the repository pattern and dependency injection using the Unity application block. It was written for various demos in presentations done by Maarten Balliauw. CarTrackr is an online software application designed to help you understand and track your fuel usage and kilometers driven. You will have a record on when you filled up on fuel, how many kilometers you got in a given tank, how much you spent and how much liters of fuel you are using per 100 kilometer.
-
Introduction to ASP.NET MVC for VISUG - Presentation materials
Yesterday evening, I did a presentation on the ASP.NET MVC framework for VISUG (Visual Studio User Group Belgium). I really hope everyone got a good feel on what the ASP.NET MVC framework is all about and what it takes to build an ASP.NET MVC application. Thank you Pieter Gheysens for inviting me for this talk! And thank you audience for being interested for over an hour and a half! A recorded version of this presentation will be available later, for the moment you'll have to do with the presentation materials. The download contains the slides, the Hello World application and the testing demo. The CarTrackr application can be found on CodePlex. Presentation materials: VISUG ASP.NET MVC materials.zip (5.63 mb) CarTrackr sample application: http://www.codeplex.com/CarTrackr/
-
Using the ASP.NET MVC ModelBinder attribute - Second part
Just after the ASP.NET MVC preview 5 was released, I made a quick attempt to using the ModelBinder attribute. In short, a ModelBinder allows you to use complex objects as action method parameters, instead of just basic types like strings and integers. While my aproach was correct, it did not really cover the whole picture. So here it is: the full picture. First of all, what are these model binders all about? By default, an action method would look like this: [code:c#] public ActionResult Edit(int personId) { // ... fetch Person and do stuff } [/code] Now wouldn't it be nice to pass this Person object completely as a parameter, rather than obliging the controller's action method to process an id? Think of this: [code:c#]
-
Forms interaction with ASP.NET MVC (screencast)
Abstract: "This screencast is a short demonstration on how you can handle form interactions using the ASP.NET MVC framework." Download sample code: MvcCommentForm.zip (593.58 kb)
-
ASP.NET MVC preview 5's AntiForgeryToken helper method and attribute
The new ASP.NET MVC preview 5 featured a number of new HtmlHelper methods. One of these methods is the HtmlHelper.AntiForgeryToken. When you place <%=Html.AntiForgeryToken()%> on your view, this will be rendered similar to the following: [code:c#] <input name="__MVC_AntiForgeryToken" type="hidden" value="Ak8uFC1MQcl2DXfJyOM4DDL0zvqc93fTJd+tYxaBN6aIGvwOzL8MA6TDWTj1rRTq" /> [/code] When using this in conjunction with the action filter attribute [ValidateAntiForgeryToken], each round trip to the server will be validated based on this token. [code:c#] [ValidateAntiForgeryToken] public ActionResult Update(int? id, string name, string email) { // ... } [/code]
-
Using the ASP.NET MVC ModelBinder attribute
ASP.NET MVC action methods can be developed using regular method parameters. In earlier versions of the ASP.NET MVC framework, these parameters were all simple types like integers, strings, booleans, … When required, a method parameter can be a complex type like a Contact with Name, Email and Message properties. It is, however, required to add a ModelBinder attribute in this case. Here’s how a controller action method could look like: [code:c#] public ActionResult Contact([ModelBinder(typeof(ContactBinder))]Contact contact) { // Add data to view ViewData["name"] = contact.Name; ViewData["email"] = contact.Email; ViewData["message"] = contact.Message; ViewData["title"] = "Succes!"; // Done! return View(); } [/code]
-
Form validation with ASP.NET MVC preview 5
In earlier ASP.NET MVC previews, form validation was something that should be implemented "by hand". Since the new ASP.NET MVC preview 5, form validation has become more handy. Let me show you how you can add validation in such a ridiculously easy manner. Here's an example controller: [code:c#] using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Mvc.Ajax; namespace ValidationExample.Controllers { [HandleError] public class HomeController : Controller { // ... some other action methods ... [AcceptVerbs("GET")] public ActionResult Contact() { return View(); }
-
Building an ASP.NET MVC sitemap provider with security trimming
Warning!A new version of the source code provided in this post is available here. Use this blog post as reference only. Yes, it has been a while since my last post. A nice vacation to Austria, some work to catch up, ... All excuses, I know, but I'll make it up to you with a huge blog post! If you have been using the ASP.NET MVC framework, you possibly have been searching for something like the classic ASP.NET sitemap. After you've played with it, you even found it useful! But not really flexible and easy to map to routes and controllers. Sounds familiar? Continue reading! Doesn't ring a bell? Well, continue reading, please! Feel free to download the sample code. UPDATE: A version for preview 5 can also be downloaded: MvcSitemapProvider.cs (19.46 kb)
-
MSDN Chopsticks on ASP.NET MVC (screencasts)
A while ago, KatrienDG asked me to do some screencasts on the ASP.NET MVC framework for the MSDN Chopsticks page. I've been working on 2 screencasts: an introductory talk to the ASP.NET MVC framework and a Test Driven Development story. Feel free to leave some comments! Abstract: "The ASP.NET MVC framework is a new approach to web development, based on the model-view-controller design pattern. Microsoft built this framework on top of ASP.NET to allow this alternative to work with existing features like membership caching, user controls... In this video, Maarten shows you some basics on the ASP.NET MVC framework like creating a new controller action and a view."
-
ASP.NET MVC - Upcoming preview 4 release
ScottGu just posted that there's an upcoming preview 4 release of the ASP.NET MVC framework. What I immediately noticed, is that there are actually some community concepts being integrated in the framework, yay! And what's even cooler: 2 of these new features are things that I've already contributed to the community (the fact that it these are included in the MVC framework now could be coincidence, though...). Thank you, ASP.NET MVC team! This preview 4 release seems like a great step in the evolution of the ASP.NET MVC framework. Thumbs up!