I have a form within my Asp.Net MVC application which returns a Null reference exception at the following line, but only after postback errors:
<%= Html.TextArea("Description", Model.Evt.Description ?? "")%>
The string Description is indeed null, but my expectation was that if Model.evt.Description is null then "" will be shown in the TextArea. Why is it doing this when it works fine on initially loading the form?
The only difference is that the type of ViewUserControl is is populated from a new object for initial load and the model object on postback reload.
What am I missing?
The Stack Trace is as follows:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.Mvc.HtmlHelper.GetModelStateValue(String key, Type destinationType) +63
System.Web.Mvc.Html.TextAreaExtensions.TextAreaHelper(HtmlHelper htmlHelper, String name, Boolean useViewData, String value, IDictionary`2 implicitAttributes, IDictionary`2 explicitParameters, IDictionary`2 htmlAttributes) +261
System.Web.Mvc.Html.TextAreaExtensions.TextArea(HtmlHelper htmlHelper, String name, String value, IDictionary`2 htmlAttributes) +213
System.Web.Mvc.Html.TextAreaExtensions.TextArea(HtmlHelper htmlHelper, String name, String value) +61
ASP.views_events_eventform_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\Documents and Settings\Richard Box\My Documents\Visual Studio 2008\Projects\EventsManager\EventsManager\Views\Events\EventForm.ascx:64
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Control.Render(HtmlTextWriter writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +59
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266