ASP.NET MVC: How to Deal with Null objects in View

asp.net-mvc

Should model objects that go to the view be checked for null before going to view? And if null, create a dummy instance? Or should the View check for null?

Best Solution

My opinion is that the Null Object pattern is a Good Thing™. Using this, you can code your View to deal with Foo objects, and all of them (including the null one) will act right.

The beauty of this pattern is that it works whether a null value is possible only alone, or as part of a collection (though the latter case should be, IMHO, very rare).