MVC Model property resets on page submit
I'm new to MVC so this may sound silly, but here goes: I have a model that
contains two lists that need to be passed to an edit form:
public class BaseViewModel
{
public IEnumerable<portal_notifications_types> Types { get; set; }
public IEnumerable<portal_notifications_importances> Importances {
get; set; }
}
In the edit form, i Have two dropdownlists for this fields:
@Html.DropDownListFor(m => m.Notification.TypeId, new
SelectList(Model.Types, "Id", "Type"), "-- Select type --", new { onchange
= "GetNotifType();", style = "width:150px;" })
@Html.DropDownListFor(m => m.Notification.ImportanceId, new
SelectList(Model.Importances, "Id", "Importance"), "-- Select importance
--", new { style = "width:150px;" })
When I first enter the edit view, everything is ok, the dropdownlists are
populated and the corresponding value is selected. However, when I submit
the form, the dropdownlists throw an error, because the Model.Types and
Model.Importances lists are null. How could I overcome this ? I would like
to avoid using ViewBag to store those lists, although I know it would
work.
No comments:
Post a Comment