1 Why do I get a NRE?
I'm guessing, but your reference to 'PostBack' might mean that you come from a WebForms background. In MVC, controller actions must always return the FULL state required to render the view (e.g. in the ViewModel), even after a POST:
[HttpPost]
ActionResult Create(DeliveryRequestViewModel someModel)
{
// Do something
return View("SomeView", someModel); <-- Remember to pass the ViewModel again
}
2 Re : Model vs model
Please point my error, why is when I use the Model with capital at the first letter I get a null exception error. Thank you very much
Model
is an instance of the type of the page's model - DeliveryRequestViewModel
in this case. (From Inherits="ViewPage<DeliveryRequestViewModel>
of the .aspx, or from @model
in razor)
Whereas in this case:
<%: Html.EditorFor(model => model.Address) %>
model
is a placeholder variable for a lambda expression which projects the Address
property off the variable. Placeholder, because it could be anything, e.g.
Html.EditorFor(foo => foo.Address)
3 Re:Readonly Text Box
Also, I guess you could just use Html.DisplayFor
if you just want to render the value?