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?
Type = model. Type. Trim(); whenever null values coming from the database occurs.
There are four ways to pass the data from View to Controller which are explained below: Traditional Approach: In this approach, we can use the request object of the HttpRequestBase class. This object contains the input field name and values as name-value pairs in case of the form submit.
How about returning a different view if the object is null?
if(object == null)
{
return View("notfound");
}
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With