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. You use view data in an ASP.NET MVC application to pass data from a controller action to a view. You […]

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. In this tip, I recommend a […]

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. When you create an MVC route, you can […]

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. In this tip, I demonstrate how you can create a custom controller that […]

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. Caching is the most effective way to improve the performance of an ASP.NET MVC application. The slowest operation that […]

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. Eric Hexter — who has done valuable work on the MvcContrib project — visited Microsoft last week and showed me one […]

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. One of the beautiful things about […]

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. The more of your web application that you can test, the more confident that you can be […]

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. Until today, I thought that a controller action could return a view from only one of two places: · Viewscontroller name · ViewsShared For […]

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. I’ve talked to several people recently who are deeply bothered by the fact that the […]

If you liked this blog entry then please Subscribe to My Blog or Follow Me on Twitter