MVC, LINQ, and WinHost
May 3, 2011 Leave a comment
I love MVC. I recently had to make some changes to the swim team website to get ready for the 2011 season. Because there was a nice SOC enforced by MVC, I simply had to add a couple of new controllers with some basic CRUD:
add their associated views, and then wire up to my factory using my POCOs:
public ActionResult Index(int? page) { FamilyFactory familyFactory = new FamilyFactory(); IQueryable<Family> families = familyFactory.GetAllFamilies() .OrderBy(family => family.FamilyDesc) .AsQueryable <Family>(); const int pageSize = 10; var paginatedFamilies = new PaginatedList<Family>(families, page ?? 0, pageSize); return View(paginatedFamilies); }
(note that I used the paginated list from Nerd Dinner)
Boom goes the dynamite.
Upon reflection, you can really see how useful using POCOs are when you have to extend your application. That upfront cost 2 years ago is paying huge dividends now.
I did run into 1 small hiccup when I deployed to WinHost. I received the following error:
After some digging (this error does not Google well), I added this:
<trust level="Full" />
To System.Web and things corrected.