background preloader

MVC

Facebook Twitter

Paging with ASP.NET MVC. Updated 2012-04-23: Version 2.0: Updated 2011-05-12: Added NuGet package: Updated 2011-03-22: Changed download link: See also Updated 2009-02-04: Upgraded source and demo to ASP.NET MVC RC1 Updated 2009-01-16: Upgraded source and demo to ASP.NET MVC Beta Updated 2008-09-09: Source and Demo now use ASP.NET MVC preview 5 On my latest gig, we used ASP.NET MVC and it was a very pleasant experience!

Paging with ASP.NET MVC

Of course, since ASP.NET MVC isn’t finished yet, it leaves something to desire. I’m in a hurry, take me to the download immediately IPagedList<T> First, there was the PagedList<T> that Scott Guthrie already used in one of the earliest MVC demo’s and that later appeared in improved incarnations from Rob Conery and Troy Goode.

Html.Pager() After choosing the IPagedList<T> implementation I started thinking about how I could create an HtmlHelper extension method that renders the page links. We’re assuming that the page links point to the the current controller and current action. Results in this: That’s it. How we do MVC – View models. A while back, I went over a few of the patterns and opinions we’ve gravitated towards on our current large-ish ASP.NET MVC project, or, how we do MVC.

How we do MVC – View models

Many of these opinions were forged the hard way, by doing the wrong thing many times until we found the “right” opinion. Of course, many of these opinions are only really valid in the constraints of our project. While the domain of this project isn’t important, here are some key aspects to consider: AJAX is used very, very sparingly. Section 508 compliance is requiredXHTML compliance is also requiredXHTML DTD validation is also requiredAll (well, 99%) operations revolve a single uber-entity. Given these constraints, these opinions may or may not apply to the project you work on. That said, I’m going to go over some of the main aspects of our MVC usage in a series of posts – starting with ViewModels.

ViewModel design For our application, the ViewModel is a central aspect of our MVC architecture. Sidenote – the term DTO is far overused. Unity.Mvc3 1.2. Dependency Injection in ASP.NET MVC 4 and WebAPI using Unity. In this post, I will demonstrate how to use Dependency Injection in ASP.NET MVC 4 application and WebAPI using Unity.

Dependency Injection in ASP.NET MVC 4 and WebAPI using Unity

The new ASP.NET MVC 4 is a great framework for building web applications and WebAPI is a great for building HTTP services. I will use Unity IoC container to provide the integration with ASP.NET MVC 4 and WebAPI for applying dependency injection. Using Unity in ASP.NET MVC 4 The following command in the Package Manager console will install Unity.Mvc3 package into your ASP.NET MVC 4 WebAPI application. PM > Install-Package Unity.Mvc3 Unity.Mvc3 is a package that allows simple Integration of Microsoft's Unity IoC container with ASP.NET MVC 3. After installation of the package you will find the Bootstrapper.cs file in the root of your ASP.NET MVC 4 WebAPI project. We will return to this class a little bit later. Using Unity in ASP.NET MVC 4 WebAPI Unfortunately Unity.Mvc3 doesn't change the DependencyResolver for WebAPI.

PM > Install-Package Unity.WebAPI Create service That's all.