Archives
-
ASP.NET MVC Design Gallery at www.ASP.net
We just launched a new Design Gallery for ASP.NET MVC websites at:
-
Back from Tech-Ed EMEA
I just flew back from Barcelona where I gave three talks last week at Tech-Ed EMEA. Lots of excitement, and great feedback, on all of the new Ajax features being added to the ASP.NET framework. I've included the Power Points and demo code from my presentations below.
-
jQuery and ASP.NET AJAX Demo Code
Thank you to everyone who came to my jQuery and ASP.NET AJAX PDC talk! As promised, I've added a link to the demo code from the talk to this blog entry.
-
Essential Visual Studio Tips & Tricks that Every Developer Should Know
In this blog entry, I list the essential tips and tricks that every developer who uses Visual Studio 2008 should know. I wanted to keep this list brief. I also wanted to focus on only those tips and tricks that I use on a daily basis. Almost all of these tips and tricks are just as useful regardless of whether you are building an ASP.NET Web Forms or ASP.NET MVC application.
-
A Guide to Learning ASP.NET MVC Beta 1
Now that ASP.NET MVC Beta 1 is out, how do you learn how to use it? How do you learn how to build ASP.NET MVC applications? Here are my recommendations.
-
jQuery in ASP.NET Talk at PDC
Mark your calendars and come to my jQuery in ASP.NET talk at PDC. It looks like my talk is scheduled for Tuesday (10/28/2008) at 5:15pm. You can still register for the PDC here:
-
New ASP.NET MVC Tutorials
I created three new ASP.NET MVC tutorials that were just published at the www.ASP.net/mvc website. There are both C# and VB.NET versions of each tutorial. Here are the direct links and descriptions:
-
ASP.NET MVC Tip #45 – Use Client View Data
In this tip, I explore one approach to building Ajax applications with ASP.NET MVC. I show how you can use view data when building Ajax applications with ASP.NET MVC in the same way as you would use view data when building server-side application. I demonstrate how to create a custom HTML Helper that renders client view data.
-
ASP.NET MVC Application Building: Family Video Website #5 – Multiple File Upload with Progress
In this series of tutorials, I build an entire ASP.NET MVC application from start to finish. In this entry, I add a Silverlight file upload control to make it easier to upload multiple media files.
-
ASP.NET MVC Application Building: Forums #6 – Ajax
In this series of blog entries, I build an entire MVC Forums application from start to finish. In this entry, I create the user interface for the Forums application by taking advantage of ASP.NET AJAX client templates. I build the entire user interface for the Forums application with a single view and perform all updates to the view with Ajax calls.
-
ASP.NET MVC Application Building: Family Video Website #4 – Paging, Silverlight and Flip
(ASP.NET MVC + Silverlight + Flip Video) is a wonderful combination! In this blog entry, I continue building the Family Video Website. I integrate a new Silverlight video player, demonstrate how to upload Flip videos, and add paging.
-
ASP.NET MVC Tip #44 – Create a Pager HTML Helper
In this tip, I demonstrate how you can create a custom HTML Helper that you can use to generate a user interface for paging through a set of database records. I build on the work of Troy Goode and Martijn Boland. I also demonstrate how you can build unit tests for HTML Helpers by faking the HtmlHelper class.
-
ASP.NET MVC Application Building: Forums #5 – Membership
In this series of blog posts, I build an entire ASP.NET MVC Forums application from start to finish. In this post, I explain how to test and implement authentication and authorization for the Forums application.
-
ASP.NET MVC Tip #43 – Use Data Annotation Validators
In this tip, I demonstrate how to take advantage of the validators from the System.ComponentModel.DataAnnotations namespace in an MVC application. You can take advantage of these validators to validate form data before submitting the form data into a database.
-
ASP.NET MVC Tip #42 – Use the Validation Application Block
In this tip, I demonstrate how you can use the Microsoft Enterprise Validation Application Block within an MVC application to perform both basic and advanced form validation. The Validation Application Block supports a rich set of validators that you can begin using in an ASP.NET MVC application.
-
ASP.NET MVC Application Building: Forums #4 1/2– Validation Revisited
I received a lot of feedback on my last blog entry on implementing server-side form validation for the MVC Forums application. Thank you everyone for the feedback!
-
ASP.NET MVC Application Building: Forums #4 – Server-Side Form Validation
In this series of blog entries, I build an entire ASP.NET MVC forums application from start to finish. In this blog entry, I add server-side form validation to the forums application.
-
ASP.NET MVC Tip #41 – Create Cascading Dropdown Lists with Ajax
In this tip, I demonstrate three methods of creating cascading drop down lists in an MVC application. First, I demonstrate how to write JavaScript code to update one dropdown list when another dropdown list changes. Next, I show you how you can retrieve the data for the dropdown lists from either a controller action or a web service.
-
ASP.NET MVC Application Building: Forums #3 – Post Messages
In this series of blog entries, I build an entire ASP.NET MVC forums application from start to finish. In this blog entry, I add the functionality to the Forums application that enables users to post new messages and replies.
-
ASP.NET MVC Application Building: Forums #2 – Create the First Unit Test
In this series of blog entries, I build an entire ASP.NET MVC Forums application from scratch. In this blog entry, I create my first unit test for the Forums application and implement the code necessary to pass the test.
-
ASP.NET MVC Application Building: Forums #1 – Create the Perfect Application
In this series of blog entries, I build an entire ASP.NET MVC Forums application from start to finish. The goal is to discover and promote best-practices for building applications with the ASP.NET MVC framework.
-
ASP.NET MVC Application Building: Family Video Website #3 – Play Videos with Silverlight
In this series of blog entries, I build an entire ASP.NET MVC application from start to finish. In this entry, I integrate the Silverlight Media Player into the Family Videos MVC application so I can play videos.
-
ASP.NET MVC Tip #40 - Don’t Cache Pages that Require Authorization
In this tip, Stephen Walther warns you to avoid making a mistake that can result in private data being displayed to unauthorized users.
-
ASP.NET MVC Tip #39 – Use the Velocity Distributed Cache
Improve the performance of ASP.NET MVC applications by taking advantage of the Velocity distributed cache. In this tip, I also explain how you can use Velocity as a distributed session state provider.
-
ASP.NET MVC Tip #38 – Simplify LINQ to SQL with Extension Methods
In this tip, Stephen Walther demonstrate how you can create new LINQ to SQL extension methods that enable you to dramatically reduce the amount of code that you are required to write for typical data access scenarios.
-
The Evolution of MVC
Take Model-View-Controller as an example. It's often referred to as a pattern, but I don't find it terribly useful to think of it as a pattern because it contains quite a few different ideas. Different people reading about MVC in different places take different ideas from it and describe these as 'MVC'. If this doesn't cause enough confusion you then get the effect of misunderstandings of MVC that develop through a system of Chinese whispers. – Martin Fowler, GUI Architectures (http://www.martinfowler.com/eaaDev/uiArchs.html)
-
ASP.NET MVC Tip #37 – Create an Auto-Complete Text Field
In this tip, Stephen Walther demonstrates how you can create an auto-complete text field in an MVC view by taking advantage of the Ajax Control Toolkit. He explains how you can create a custom Ajax Helper that renders the necessary JavaScript.
-
ASP.NET MVC Tip #36 – Create a Popup Calendar Helper
In this tip, Stephen Walther demonstrates how you can create a JavaScript popup calendar (date picker) that works within an ASP.NET MVC view. The calendar is created with the AJAX Control Toolkit.
-
New ASP.NET MVC Videos and Tutorials
15 new ASP.NET MVC videos were just published at the http://www.ASP.net/mvc website. The first 10 videos are basic tutorials on the ASP.NET MVC framework. If you haven’t had a chance to play with ASP.NET MVC yet, these tutorials are a great introduction.
-
ASP.NET MVC Tip #35 – Use the NHaml View Engine
In this tip, I explain how you can use the NHaml view engine as the view engine for an ASP.NET MVC application. I demonstrate how to create NHaml views that display both static content and database records. I also discuss how you can use master pages and user controls with the NHaml view engine.
-
ASP.NET MVC Tip #34 – Dispose of Your DataContext (or Don’t)
In this tip, I demonstrate how you can dispose of a DataContext within an ASP.NET MVC controller. Next, I argue that there is no compelling reason to do this.
-
ASP.NET MVC Tip #33 – Unit Test LINQ to SQL
In this tip, I demonstrate how to unit test the LINQ to SQL DataContext object by creating a Fake DataContext. You can perform standard LINQ to SQL inserts, updates, deletes and LINQ queries against the Fake DataContext.
-
ASP.NET MVC Application Building #2: Family Video Website – Add the Database
In this series of blog entries, I build an entire ASP.NET MVC application from start to finish. I create a Family Video Website that you can use to host home videos and photographs.
-
ASP.NET MVC Tip #32 – Repopulate Form Fields with ViewData.Eval()
When you need to repopulate the form data in an edit form, displaying both valid and invalid values, use ViewData.Eval() to retrieve the values from both the view data dictionary and the view data Model.
-
ASP.NET MVC Tip #31 – Passing Data to Master Pages and User Controls
In this tip, I discuss four strategies for passing data to Master Pages and User Controls. I explain how you can pass data by using a code-behind class, by using an action filter, by using method calls, and by using abstract controller base classes. I recommend the final strategy.
-
ASP.NET MVC Tip #30 – Create Custom Route Constraints
In this tip, I show how you can create custom route constraints that prevent you from accessing a URL unless you are local and authenticated. I show you how you can create a LocalConstraint and an AuthenticatedConstraint. I also demonstrate how you can test your custom constraints.
-
ASP.NET MVC Tip #29 – Build a Controller to Debug Your Custom Routes
In this tip, I demonstrate how you can create a special controller that you can use to test your custom routes. I also explain how you can give your routes back their names so you can more effectively unit test your routes.
-
ASP.NET MVC Application Building #1: Family Video Website – Upload the Videos
In this series of blog entries, I build an entire ASP.NET MVC application from start to finish. I create a Family Video Website that you can use to host home videos and photographs.
-
ASP.NET MVC Tip #28 – Test If Caching Is Enabled
In this tip, I demonstrate how you can test if the OutputCache attribute is present on a controller action. I also demonstrate how you can test if the OutputCache attribute is set with a particular duration.
-
ASP.NET MVC Tip #27 – Create ASP.NET MVC Specific Visual Studio Add-Ins
In this tip, I discuss Eric Hexter’s TDD Class Generator Add-In for Visual Studio. This Add-In enables you to generate a class, an interface, and a test class by entering a single keyboard shortcut.
-
ASP.NET MVC Tip #26 – Create a Lightweight Control View Engine
In this tip, I show you how to create a custom ASP.NET MVC view engine that supports lightweight, declarative controls. I show you how to create both simple controls and controls that display database data. I also show you how to test the rendered output of the lightweight controls.
-
ASP.NET MVC Tip #25 – Unit Test Your Views without a Web Server
In this tip, I demonstrate how you can unit test ASP.NET MVC views without running a Web server. I show you how to unit test views by creating a custom MVC View Engine and a fake Controller Context.
-
ASP.NET MVC Tip #24 – Retrieve Views from Different Folders
In this tip, I demonstrate how you can retrieve a view from any folder in an ASP.NET MVC application. I show you how to use both specific paths and relative paths.
-
ASP.NET MVC Tip #23 – Use POCO LINQ to SQL Entities
In this tip, I demonstrate how you can create LINQ to SQL entities that do not contain any special attributes. I show you how you can use an external XML file to map LINQ to SQL entities to database objects.
-
ASP.NET MVC Tip #22 -- Return a View without Creating a Controller Action
In this tip, I demonstrate how you can eliminate controller methods that simply return views. I show you how to use the HandleUnknownAction method to handle every request against a controller automatically.
-
ASP.NET MVC Tip #21 – Fake the Data Context
In this tip, I demonstrate how to create an in-memory data context class that you can use when unit testing ASP.NET MVC applications that access a database.
-
ASP.NET MVC CodePlex Preview 4
Fantastic! A new version of the ASP.NET MVC framework was released on CodePlex today. This new version of ASP.NET MVC includes support for error handling, authorization, caching, and Ajax.
-
ASP.NET MVC Tip #20 – How to Unit Test Data Access
In this tip, I demonstrate how you can write unit tests for MVC controller actions that access a database. I show you how to create unit tests for your LINQ to SQL controller action code.
-
ASP.NET MVC Tip #19 – Use the nVelocity View Engine
In this tip, I demonstrate how you can use the nVelocity view engine, instead of the normal Web Forms view engine, when displaying views from an ASP.NET MVC application.
-
ASP.NET MVC Tip #18 – Parameterize the HTTP Context
Context is the enemy of testability. In this tip, I demonstrate how you can eliminate, once and for all, the HTTP Context from an ASP.NET MVC application.
-
ASP.NET MVC Tip #17 – How to Run an ASP.NET MVC Application
In this tip, I explain the different options for running an ASP.NET MVC application from Visual Studio 2008. I recommend that you run an ASP.NET MVC application directly from the ASP.NET Development Web Server.
-
ASP.NET MVC Tip #16 – Create ASP.NET MVC Macros
In this tip, I show you how you can create a Visual Studio 2008 macro that creates a new MVC controller, view folder, and controller unit test with a single command.
-
ASP.NET MVC Tip #15 – Pass Browser Cookies and Server Variables as Action Parameters
In this tip, I demonstrate how you can pass browser cookies and HTTP server variables to controller action methods in the same way as you can pass form and query string parameters.
-
ASP.NET MVC Tip #14 – Create a Template Helper Method
In this tip, you learn how to create and use templates in the MVC framework that you can use to display database data. I show you how to create a new MVC Helper method named the RenderTemplate() method.
-
ASP.NET MVC Tip #13 – Unit Test Your Custom Routes
In this tip, I demonstrate how you can create unit tests for the routes in your ASP.NET MVC applications. I show how to test whether a URL is being mapped to the right controller, controller action, and action parameters.
-
ASP.NET MVC Tip #12 – Faking the Controller Context
In this tip, I show you how to test ASP.NET intrinsics when building unit tests for an ASP.NET MVC application. I show you how to create a standard set of fake objects that enables you to fake the current user, the current user roles, the request parameters, session state, and cookies.
-
An Introduction to xUnit.net for ASP.NET MVC Developers
The purpose of this blog entry is to provide you with an introduction to the xUnit.net unit testing framework, the newest unit testing framework for the .NET framework. I want to demonstrate how you can use the xUnit.net framework when practicing test-driven development. In particular, I focus on using xUnit.net when building an ASP.NET MVC application.
-
ASP.NET MVC Tip #11 – Use Standard Controller Action Names
In this tip, I recommend that you use standard names for your controller actions in order to make your code more transparent to other developers.
-
ASP.NET MVC Tip #10 - Prevent URL Manipulation Attacks
In this tip, I explain how hackers can steal sensitive information from an ASP.NET MVC website by manipulating URLs. I also discuss how you can build unit tests to prevent this type of attack.
-
ASP.NET MVC Tip #9 – Create a GridView View User Control
In this tip, I show you how to build an ASP.NET MVC View User Control that accepts a set of database records and renders the records in an HTML table automatically. The advantage of using a View User Control is that you can customize the rendering of particular columns.
-
ASP.NET MVC Tip #8 – Create an ASP.NET MVC GridView Helper Method
In this tip, you learn how to extend the ASP.NET MVC framework with a new helper method that displays an HTML table of database data.
-
ASP.NET MVC Tip #7 – Prevent JavaScript Injection Attacks with Html.Encode
In this tip, you learn that JavaScript Injection attacks are much more serious than you might think. I show you how to do very evil things with an ASP.NET MVC website using a JavaScript Injection attack and then I explain an easy way to prevent this type of attack.
-
ASP.NET MVC Tip #6 – Call RedirectToAction after Submitting a Form
In this tip, I explain why you should call the RedirectToAction() method after submitting form data instead of returning a view.
-
ASP.NET MVC Tip #5 – Create Shared Views
In this tip, I explain how to create shared views for controller actions. A shared view can be used with multiple controllers. In particular, I explain how to create shared views for displaying and editing database data.
-
ASP.NET MVC Tip #4 - Create a Custom Data Controller Base Class
In this tip, you learn how to create a custom controller base class that exposes actions for performing common database operations such as displaying, inserting, updating, and deleting data.
-
ASP.NET MVC Tip #3 – Provide Explicit View Names when Unit Testing
In this tip, Stephen Walther explains how you can unit test whether a controller action returns a particular view. He recommends that you be explicit about view names when you plan to create unit tests.
-
ASP.NET MVC Tip #2 - Create a custom Action Result that returns Microsoft Excel Documents
In this tip, I show you how to create a custom action result that you can return from an ASP.NET MVC controller action. This action result generates a Microsoft Excel Document from a LINQ to SQL query.
-
ASP.NET MVC Tip #1 - Create New HTML Helpers with Extension Methods
In this tip, I show you how you can create two new HTML Helpers that you can use within an ASP.NET MVC View. I show you how you can use extension methods to create new HTML Helpers for displaying bulleted and numbered lists.
-
TDD : Introduction to Moq
In this post, I provide an introduction to Moq which is the newest of the Mock Object Frameworks. Moq is promoted by its creators as easier to learn and use than other Mock Object Frameworks such as Rhino Mocks and TypeMock Isolator.
-
ASP.NET MVC Book List
I've been collecting book recommendations on software design principles and patterns, test-driven development, and agile development. I wanted to share my current reading list with you in case you are interested in learning more about these topics. If you have any additional book recommendations -- please share!
-
I’m Now Working at Microsoft
It’s official, I’m now working at Microsoft. I have an office in building 42 and they have supplied me with a phone, an email account, and a computer. I even have a whiteboard in case inspiration hits me (it currently is blank).
-
Talks: Pure AJAX Talk from ASP.NET Connections Orlando
Thank you everyone who came to my Building "Pure" Ajax Applications talk in Orlando! Here are the performance results recorded during the talk:
-
Talks: ASP.NET MVC Post Conference Workshop at ASP.NET Connections Orlando
Thank you everyone who came to my full-day workshop on ASP.NET MVC! Here is the link to the updated PowerPoint slides:
-
TDD : Introduction to Rhino Mocks
Rhino Mocks is the most popular Mock Object Framework for .NET. The purpose of this blog entry is to provide a brief introduction to Rhino Mocks. In particular, I want to describe how you can use Rhino Mocks when building ASP.NET MVC web applications.
-
TDD: Test-Driven Development with Visual Studio 2008 Unit Tests
The purpose of this blog entry is to explain how you can create unit tests by using Visual Studio 2008. I’m not interested in unit tests in general -- I’m interested in building a particular type of unit test. I want to build unit tests that can be used when following good Test-Driven Development (TDD) practices when building ASP.NET MVC Web Application projects.
-
ASP.NET MVC In-Depth: The Life of an ASP.NET MVC Request
The purpose of this blog entry is to describe, in painful detail, each step in the life of an ASP.NET MVC request from birth to death. I want to understand everything that happens when you type a URL in a browser and hit the enter key when requesting a page from an ASP.NET MVC website.
-
TDD: Introduction to Typemock Isolator
Typemock Isolator is often referred to the most powerful Mock Object Framework for .NET. I’ve heard people talk about it as “The Big Guns”, “The Nuclear Weapon”, the “Cleanup Guy”. In this blog entry, I’m going to provide you with a brief introduction to Typemock Isolator.
-
Book Review: The Art of Unit Testing
I stumbled across The Art of Unit Testing by Roy Osherove while researching Mock Object frameworks that can be used with ASP.NET MVC. Even though the author is still in the process of writing the book, you can download an early draft of this book at http://www.manning.com/osherove/.
-
Using ASP.NET AJAX with ASP.NET MVC
Yes, you can use ASP.NET AJAX with ASP.NET MVC. Several people have asked me recently how you can use ASP.NET AJAX in an ASP.NET MVC view. In this blog entry, I’m going to explain the problem and the solution.
-
ASP.NET AJAX In-Depth: Application Events
The goal of this blog entry is simple: I want to understand everything about ASP.NET AJAX Application events. I want to know how application events work under the covers by performing a close examination of the Microsoft AJAX Library source code for the Application object.
-
ASP.NET AJAX In-Depth: Object Inheritance
The goal of the blog entry is simple: I want to understand everything happening under the covers when you take advantage of ASP.NET AJAX inheritance. So, let’s start with a simple code sample:
-
Two Methods of Creating JavaScript Objects: Prototype Inheritance and the Xerox Method
In this blog entry, I examine different methods of building new JavaScript objects from existing JavaScript objects. For lack of better names, I’m calling the first method the Prototype Inheritance method and the second method the Xerox method. The goal of this blog entry is discuss the relative strengths and weaknesses of the two methods. At the very end of this entry, I briefly examine the approach taken by the ASP.NET AJAX framework.
-
ASP.NET 3.5 Unleashed Errata: Listing 31.6 and Listing 31.24
-
Declaring Client-Side ASP.NET AJAX Controls : Part I
I want to build “pure” client-side ASP.NET AJAX web applications and I want to get the full benefits of a declarative framework. Currently, the ASP.NET AJAX framework does not support a good method of creating declarative client-side controls. In this blog entry, I examine different strategies for implementing declarative client-side controls that target the Microsoft ASP.NET AJAX framework.
-
ASP.NET 3.5 Unleashed Errata: ASP.NET AJAX Authentication
Well, I guess it is too much to hope that there would not be any errors in an almost 2,000 page book. Bertrand Le Roy sent me an email pointing out a security hole in one of my code samples in ASP.NET 3.5 Unleashed. The problem is in Chapter 33, Using Client-Side ASP.NET AJAX.
-
Creating JavaScript Properties in ASP.NET AJAX
JavaScript (or more accurately, ECMAScript 3.0) does not support properties. JavaScript objects do not have properties in the same sense as C# or VB.NET objects have properties. That’s unfortunate, since there are benefits to C# and VB.NET properties:
-
JavaScript Magic Properties: Using __count__ , __proto__ , and __parent__
Two of the Mozilla implementations of the JavaScript engine, SpiderMonkey and Rhino, support a special list of magic properties. Because SpiderMonkey is the JavaScript engine used by Firefox, this means that you can use these magic properties in JavaScript code that is executed within the Firefox browser. Unfortunately, these magic properties are not supported by Microsoft Internet Explorer or Opera. There is no expectation that any browser other than a Mozilla browser will ever support these properties since the properties are not part of the ECMAScript standard that defines the JavaScript standard.