Adding items to Model Collection in ASP.NET MVC
Posted
by Stacey
on Stack Overflow
See other posts from Stack Overflow
or by Stacey
Published on 2010-03-26T21:32:29Z
Indexed on
2010/03/26
21:43 UTC
Read the original article
Hit count: 267
asp.net-mvc-2
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.
© Stack Overflow or respective owner