Tag: CSharp
All the articles with the tag "CSharp".
-
Using the ASP.NET MVC ModelBinder (screencast)
A new screencast has just been uploaded to the MSDN Belgium Chopsticks page. Don't forget to rate the video! Abstract: "This screencast demonstrates how code can be made more maintainable and testable by delegating binding to client data to the ASP.NET MVC model binder architecture."
-
Partial page updates with ASP.NET MVC and jQuery (and action filters)
When building an ASP.NET MVC application, chances are that you are using master pages. After working on the application for a while, it's time to spice up some views with jQuery and partial updates. Let's start with an example application which does not have any Ajax / jQuery. Our company's website shows a list of all employees and provides a link to a details page containing a bio for that employee. In the current situation, this link is referring to a custom action method which is rendered on a separate page. The company website could be made a little sexier... What about fetching the employee details using an Ajax call and rendering the details in the employee list? Yes, that's actually what classic ASP.NET's UpdatePanel does. Let's do that with jQuery instead.
-
Integrating NUnit test results in Team Build 2008
When using Team Foundation Server 2008 and Team Build, chances are you are developing unit tests in Microsoft’s test framework which is integrated with Visual Studio 2008. This integration offers valuable data hen a build has been finished on the build server: test run results are published in the Team Foundation Server 2008 data warehouse and can be used to create detailed metrics on how your development team is performing and what the quality of the product being developed is.
-
Creating a generic Linq to SQL ModelBinder for the ASP.NET MVC framework
You are right! This is indeed my third post on ASP.NET MVC ModelBinders. The first one focussed on creating a ModelBinder from scratch in an older preview release, the second post did something similar trying to do some dirty ViewState-like stuff. Good news! There's more of this dirty stuff coming! How about this action method, using a Person class which is a Linq to SQL entity type: [code:c#] public ActionResult PersonDetails(Person id) { if (id == null) return RedirectToAction("Index"); return View(id); } [/code]
-
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]