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?
A:
You shouldn't need to check for nulls. If your getting your data in your controller via a list, it should only return actual db results as objects. If there are no records you can always check for a 0 count in your view and display a message, along the lines of
<% if (ViewData.Model.Count == 0) { %>
No results found.
<% } %>
rXc3NtR1c
2009-05-18 02:58:09
+3
A:
How about returning a different view if the object is null?
if(object == null)
{
return View("notfound");
}
Skiltz
2009-05-18 05:24:49
A:
It's a special case when your Model is null - so you should either throw an exception or create a default Model (or maybe return a special View). I think you should always provide a Model instance to View if it require a Model.
eu-ge-ne
2009-05-18 19:56:27