Adding items to Model Collection in ASP.NET MVC
- by Stacey
In an ASP.NET MVC application where I have the following model..
public class EventViewModel
{
public Guid Id { get; set; }
public List<Guid> Attendants { get; set; }
}
passed to a view...
public ActionResult Create(EventViewModel model)
{
// ...
}
I want to be able to add to the "Attendants" Collection from the View. The code to add it works just fine - but how can I ensure that the View model retains the list? Is there any way to do this without saving/opening/saving etc? I am calling my addition method via jQuery $.load.
public void Insert(Guid attendant)
{
// add the attendant to the attendees list of the model - called via $.load
}
I would also like to add there is no database. There is no storage persistence other than plain files.