title: Updating model from view
body: <p>Working on my first MVC ASP.NET project. I am wondering how I can update the model using user's inputs.</p>
  
  <p>Let's say I have a model PersonModel.cs</p>
  
  <pre><code>public class PersonModel
  {
      int personID;
      string firstName;
      string lastName;
      string favoriteColor;
  
      public PersonModel(int personID){
      this.PersonID=personID;
      //..Fetching data from DB to fill firstName and lastName using personID
      //At this point, personID,firstName and lastName are set, only the favoriteColor is missing
      }
  }
  </code></pre>
  
  <p>Now my controller:</p>
  
  <pre><code>public class PersonController : Controller
  {
      public ActionResult Index() {
      PersonModel person = new PersonModel(this.UserId());
  
      return View(person);
  }
  </code></pre>
  
  <p>In my View :</p>
  
  <pre><code>@using Portail.Models
  @model PersonModel
  
  @ViewBag.Title = "Welcome page"
  
  &lt;h2&gt; Hello @Model.firstName @Model.lastName &lt;/h2&gt;        
  </code></pre>
  
  <p>For now it's working fine, displaying the first and last names of the user, according to the values in the DB.</p>
  
  <p>I would like the user to choose a color in a list and then set this color as the favoriteColor variable in the model, and then update the DB with it. For example, by adding a drop down list:</p>
  
  <pre><code>&lt;select&gt;
    &lt;option value="red"&gt;Red&lt;/option&gt;
    &lt;option value="blue"&gt;Blue&lt;/option&gt;
    &lt;option value="green"&gt;Green&lt;/option&gt;
    &lt;option value="yellow"&gt;Yellow&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>How can I update my model by setting the chosen color for favoriteColor ?</p>
  
  <p>Note that this is just an example, for the project I am working on I need to update a couple of variables, not just one like it's the case here. Also, it's confidential data so I don't want to pass anything in URL.</p>