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. In my previous tip, I explained how you can take advantage of the validators included with […]
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 […]
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. Imagine that you are building a financial services website. Each user of the website can log in and view a page that lists their current investments. For example, the investments page might […]
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. The best way to improve the performance of an ASP.NET MVC application is by caching. The slowest operation that you can perform in […]
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. By taking advantage of LINQ to SQL, you can dramatically reduce the amount of code that you need […]
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. In the previous tip, I demonstrated how you can take advantage of the client […]
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. A script file only version of the AJAX Control Toolkit was just released by Microsoft at the CodePlex website: http://www.codeplex.com/AjaxControlToolkit/Release/ProjectReleases.aspx?ReleaseId=16488 This version of […]
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. Several people have emailed me recently with the same question about whether or not it is important to call Dispose() on the DataContext object. In all […]
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. In […]
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. I’ve struggled for the past couple of months with different methods of unit testing MVC controllers that return […]