Last week I was in the middle of re-writing an old MVC application. The app was written during the early days of MVC, and as a consequence it was a playground for learning and experimentation. As a developer, I am continuously learning new tricks so its’ no surprise that when I look at the code I wrote a few years ago I often refactor it. For example, when I started out with ASP.NET MVC I did not fully understand how the model binders worked. Unfortunately, this meant that some of my controller actions ended up looking like this: [HttpPost]
public ActionResult Edit( Guid id, FormCollection form )
{
var foo = new SomeModel();
foo.Id = id;
foo.Name = form["Name"];
foo.Date = DateTime.Parse(form["EffectiveDate"]);
foo.Description = form["Description"];
....
if (ModelState.IsValid)
{
...Save and redirect
}
return View(model);
}
Yuck! Referencing form collections in your controlle...
[More]
Today was a great day to be a .NET developer. I felt like a five year old on Christmas morning. I had that feeling you get when you just finished opening all your gifts and you are not sure what you want to play with first. Just in case you are living under a rock, here is a quick summary of what I found under the Christmas tree today.
MVC 3 – Its Finally Here
Today MVC3 with Razor was released. This means that we can finally avoid paying the angle bracket tax. The new razor syntax will make writing HTML a much more pleasant experience. Here are some of the highlights. For full details read the release notes:
Razor – Razor is a new concise syntax that is clean, fast and easy to use. The best part is that you can mix Razor and WebForm pages. This gives you the ability to gradually upgrade your existing MVC apps. Microsoft hit a homerun on this one.
Improved View Scaffolding
Unobtrusive jQuery support for validation and AJAX calls
Also make sure to check ou...
[More]
Let's face it, if you are a .NET web developer then jQuery is quickly becoming a required skill. With that said, I am making it a point this year to learn as much as I can about jQuery. If this was some sort of support meeting then this would be the part where I would stand up and say "Hi, I am an MVC addict, and my New Year's resolution is to become a jQuery ninja." LOL Anyways, over the last couple of days I have spent time digging through the various jQuery tips and tricks that are scattered on the web. Here are a few tips and tricks that I found particularly interesting that I wanted to share with you: No conflict-mode (No, this is not a tip about dating or parenting) To avoid conflict when you are using multiple libraries in a website, you can use this jQuery Method, and assign a different variable name instead of the dollar sign. Using jQuery with other libraries var $j = jQuery.noConflict();
$j('#myDiv').hide();
Using empty() vs html("") ...
[More]
Traditionally when you think about a database you think of tables, views, indexes and stored procedures. If you have made a career out of developing database centric applications like I have, then chances are that you have spent a great deal of time dealing with issues around referential integrity, normalization and performance.
Unless you have been living underneath a rock, then you have probably heard of the newest database trend named NoSQL. NoSQL refers to non relational document databases that help address issues like performance and scalability which are often hard to achieve when using traditional database systems such as SQL or Oracle. NoSQL replaces the old “scale up” mantra of database management with a new one: “scale out.” Instead of adding bigger servers to handle more data load, a NoSQL database allows a company to distribute the load across multiple hosts as the load increases. In case you are wondering many successful companies such ...
[More]
Chirpy Zippy – A Visual Studio add-in that Mashes, minifies, and validates your JavaScript, Stylesheet, and dotless files. Chirpy can also auto-update T4MVC and other T4 templates. In the past, I typically would run all of my script and CSS files through a compressor before deploying them to a production web server. However, with Chirpy installed, your CSS and script files will be automatically compressed based on their name. For example, if you have a script file named myscript.js that you want compressed, you would rename the script to myscript.yui.js and your file will automatically be minified using the YUI compressor. The minified file shows up as a child item in solution explorer so you still have your non-minified, human-readable scripts for debugging purposes. T4MVC - I blogged about T4MVC before but its always worth mentioning again. T4MVC is a T4 template for ASP.NET MVC apps that creates strongly typed helpers that eliminate the use of literal strings when re...
[More]