title: ASP.NET MVC Dropdownlist + save selectedvalue
body: <p>I want to load a dropdownlist with values received from my mysql database.</p>
  
  <p>This is what I have in my <strong>ViewModel</strong>:</p>
  
  <pre><code>public int ProjectID { get; set; }
  public IEnumerable&lt;SelectListItem&gt; Projects { get; set; }
  </code></pre>
  
  <p>Create function in my <strong>Controller</strong>:</p>
  
  <pre><code>public ActionResult Create(DeliverableViewModel model)
      {
          var projects = (repository.GetProjects()).ToList();
          ViewBag.Projects = projects;
  
          if (ModelState.IsValid)
          {
              try
              {
  
                  repository.AddDeliverable(model.ProjectID);
              }
              catch (ArgumentException ae)
              {
                  ModelState.AddModelError("", ae.Message);
              }
              return RedirectToAction("Index");
          }
  
          return View(model);
      }
  </code></pre>
  
  <p>I load the projects in my repository. (values: project_id and project_name)</p>
  
  <p>This is my Create <strong>View</strong>:</p>
  
  <pre><code>    @model GDMfrontEnd.Models.DeliverableViewModel
  
  @{
      ViewBag.Title = "Create";
  }
  
  &lt;h2&gt;Create&lt;/h2&gt;
  
      @using (Html.BeginForm("Create", "Deliverable", FormMethod.Post, new { enctype = "multipart/form-data" }))
      {
          @Html.ValidationSummary(true)
  
              &lt;div class="editor-field"&gt;
                   @Html.DropDownListFor(model =&gt; model.Projects,
         new SelectList(ViewBag.Projects,
          "project_id", "project_name"))
              &lt;/div&gt;
              &lt;p&gt;
                  &lt;input type="submit" value="Create" /&gt;
              &lt;/p&gt;
  
      }
  </code></pre>
  
  <p>But now, how can I give my ProjectID from the selected value to my repository?</p>