I'm new to C#, but when I'm submitting a form, I catch the form values and create a new item of it and put it in a list according to the code below:
public ActionResult Movie()
{
int id = Convert.ToInt16(Request.Form["inputmovieid"]);
string name = Request.Form["inputmovietitle"];
int year = Convert.ToInt16(Request.Form["inputproductionyear"]);
List<Movie> movies = new List<Movie>();
Movie movieitem = new Movie(id, name, year);
movies.Add(movieitem);
return View(movies);
}
In a .cshtml-file I then print the created item with a foreach loop, but the problem is that if I submit this form again with new values for a new item, it overwrites the old one in the list.
DESIRED RESULT: When submitting the form again I want a new item to be added to the list without overwriting the old one. Does anyone know how the code above can be modified to solve this?