The
@model BloombergGUI.Models.SecurityViewAltModel
you define in the View is actually a strongly typed data passing mechanism from the controller.
when you do
return View();
you should be getting a NULL Model. This is because no data is being passed to the View. Model is expected to be null.
when you do
return View(new SecurityViewAltModel());
a non-null Model object is sent with all fields null. MVC will render empty controls for these null data fields.
Note that in the second case, you might not get the Null reference exception because you're not dealing with a straight object.field reference, but an Expression.
m => m.FieldsList
vs. Model.FieldsList
Details:
- When the expression is being evaluated, there can be checks which will prevent the null reference.
Deep inside the MVC DLLs, when the Expression is being processed, it has logic as follows:
Evaluate the Value of the Expression with Parameter as viewData.Model object.
The call is as follows:
CachedExpressionCompiler.Process<TParameter, TValue>(expression)(model);
And at that time, it goes into the FingerprintingExpressionVisitor and it can handle the null Model and returns null response for the Extension helper to not render any data.