title: The values of a list are passing NULL in ASP MVC and EF
body: <p>I am developing an ASP .Net MVC 3 application using C# and SQL Server 2005. </p>
  
  <p>I am using also Entity Framework and Code First Method.</p>
  
  <p>I have some values of parametres in a form which I want to save them in a List.</p>
  
  <p>I already did that but the problem now that when I save for the next time, the new values crushs the old ones.</p>
  
  <p>So to follow that, I debug the project step by step using F10 and I found that the list became NULL in the end of execution.</p>
  
  <p>This is the code of the controller 'ProfileGaController' :</p>
  
  <pre><code>namespace MvcApplication2.Controllers
  { 
      public class ProfileGaController : Controller
      {
          private GammeContext db = new GammeContext();
  
          public ActionResult Gestion(FlowViewModel model)
          {
              return PartialView(model);
          }
  
          [HttpGet]
          public ActionResult Index(Profile_Ga profile_ga, Poste poste)
          {             
              var viewModel = new FlowViewModel();
              viewModel.PostesItems = new SelectList(db.Postes.ToList(), "ID_Poste", "ID_Poste");            
              viewModel.Profile_GaItems = db.Profil_Gas.ToList();
              viewModel.GaItems = db.Gammes.ToList();
  
              return View(viewModel);
          }
  
          public ViewResult Details(string id)
          {
              Profile_Ga profile_ga = db.Profil_Gas.Find(id);
              return View(profile_ga);
          }
  
          public ActionResult Create()
          {            
              return View();
          } 
  
          [HttpPost]
          public ActionResult Create(Profile_Ga profile_ga)
          {
              if (ModelState.IsValid)
              {
                  db.Profil_Gas.Add(profile_ga);
                  db.SaveChanges();
                  return RedirectToAction("Index");  
              }
  
              return View(profile_ga);
          }
  
          public ActionResult Edit(string id)
          {
              Profile_Ga profile_ga = db.Profil_Gas.Find(id);
              return View(profile_ga);
          }
  
          [HttpPost]
          public ActionResult Edit(Profile_Ga profile_ga)
          {
              if (ModelState.IsValid)
              {
                  db.Entry(profile_ga).State = EntityState.Modified;
                  db.SaveChanges();
                  return RedirectToAction("Index");
              }
              return View(profile_ga);
          }
  
          public ActionResult Delete(string id)
          {
              Profile_Ga profile_ga = db.Profil_Gas.Find(id);
              return View(profile_ga);
          }
  
          [HttpPost, ActionName("Delete")]
          public ActionResult DeleteConfirmed(string id)
          {            
              Profile_Ga profile_ga = db.Profil_Gas.Find(id);
              db.Profil_Gas.Remove(profile_ga);
              db.SaveChanges();
              return RedirectToAction("Index");
          }
  
          protected override void Dispose(bool disposing)
          {
              db.Dispose();
              base.Dispose(disposing);
          }
  
          [HttpPost]
          public ActionResult Save(FlowViewModel model)
          {
  
              if (ModelState.IsValid)
              {
                  Gamme G = new Gamme();
                  G.ID_Gamme = model.SelectedProfile_Ga;
                  G.ID_Poste = model.SelectedPoste;
  
                  G.Next_Posts = model.PosteSuivantSelected;
                  G.Nbr_Passage = int.Parse(model.Nbr_Passage);
                  G.Position = int.Parse(model.Position);
                  model.ListG.Add(G);
              }
              return RedirectToAction("Index");           
          }
      }
  }
  </code></pre>
  
  <p>This is the code of the view model 'FlowViewModel' :</p>
  
  <pre><code>public class FlowViewModel
  {    
      [Key]
      public string IDv { get; set; }
      [NotMapped]
      public SelectList PostesItems { get; set; }
      public List&lt;Profile_Ga&gt; Profile_GaItems { get; set; }
      public List&lt;Gamme&gt; GaItems { get; set; }
      public string SelectedProfile_Ga { get; set; }
      public string SelectedPoste { get; set; }    
      public string PostePrecedentSelected { get; set; } 
      public string PosteSuivantSelected { get; set; }
      public string Position { get; set; }
      public string  Nbr_Passage { get; set; }           
      public List&lt;Gamme&gt; ListG = new List&lt;Gamme&gt;(); 
  }
  </code></pre>
  
  <p>This is the code of the partial view Gestion.ascx :</p>
  
  <pre><code>&lt;%@  Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;MvcApplication2.Models.FlowViewModel&gt;" %&gt;
  &lt;% using (Html.BeginForm("Save", "ProfileGa")) { %&gt;
      &lt;%: Html.ValidationSummary(true) %&gt;
      &lt;fieldset class="parametrage"&gt;
          &lt;legend&gt;Gestion de Gamme&lt;/legend&gt;
  
          &lt;div&gt;
          &lt;%:Html.Label("Poste :")%&gt;&lt;%: Html.DropDownListFor(model =&gt; model.SelectedPoste, Model.PostesItems)%&gt;
  
          &lt;/div&gt;
  
  
           &lt;div&gt;
           &lt;%:Html.Label("Nombre de Passage :")%&gt;&lt;%: Html.EditorFor(model=&gt;model.Nbr_Passage)%&gt;
           &lt;/div&gt;
           &lt;div class="editor-field"&gt;
            &lt;%: Html.ValidationMessageFor(model =&gt; model.Nbr_Passage)%&gt;
            &lt;/div&gt;
  
          &lt;div&gt;
          &lt;%:Html.Label("Position :")%&gt;&lt;%: Html.EditorFor(model=&gt;model.Position)%&gt;
          &lt;/div&gt;
  
  
          &lt;div&gt;
          &lt;%:Html.Label("Poste Suivant :")%&gt;&lt;%: Html.DropDownListFor(model =&gt; model.PosteSuivantSelected, Model.PostesItems, new { @id = "dd" })%&gt;
  
          &lt;/div&gt;
  
  
          &lt;div&gt;
          &lt;input type="submit" value="Enregistrer" id="btnSave"  /&gt;
          &lt;/div&gt;
  
          &lt;/fieldset&gt;
  </code></pre>