title: MVC : Binding datetime value (bootstrap datetime picker) from view to model
body: <p>I want to bind the date time value that I get from view to my model, so that I could use to save it in database.<br>
  Note: Currently I'm using bootstrap datetime picker to get date time value.<br>
  Let us say I have a ViewModel called foo</p>
  
  <pre><code>public class fooVM
  {
    public string Name {get; set; }
  
    [DataType(DataType.DateTime)]
    public DateTime DateEntered {get; set}
  }
  </code></pre>
  
  <p>based on this I have a view</p>
  
  <pre><code>@model User.Model.fooVM
  @{
      ViewBag.Title = "Create";
      Layout = "~/Views/shared/_BootstrapLayout.basic.cshtml";
  }
  @section Datetime
  {
      &lt;link href="@Url.Content("~/Content/bootstrap.css")" rel="stylesheet" type="text/css"/&gt;
      &lt;link href="@Url.Content("~/Content/bootstrap-datetimepicker.min.css")" rel="stylesheet" type="text/css" /&gt;
      &lt;script type="text/javascript" src="@Url.Content("~/Scripts/jquery-2.0.2.min.js")"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="~/Scripts/bootstrap.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="~/Scripts/bootstrap-datetimepicker.min.js"&gt;&lt;/script&gt;
  }
    @using (Html.BeginForm("Register", "Account", FormMethod.Post))
      {
  
              &lt;div class="input-block-level"&gt;@Html.TextBoxFor(model =&gt; model.Name&lt;/div&gt;
  
  
             &lt;div id="datetimepicker2" class="input-append date"&gt;
                      &lt;input data-format="dd/MM/yyyy HH:mm:ss PP" type="text"/&gt;
                 &lt;span class="add-on"&gt;
                     &lt;i data-time-icon="icon-time" data-date-icon="icon-calendar"&gt;&lt;/i&gt;
                 &lt;/span&gt;
  
                  &lt;/div&gt;
  
              &lt;script type="text/javascript"&gt;
                  $(document).ready(function() {
                      $('#datetimepicker2').datetimepicker({
                          format: 'dd/MM/yyyy hh:mm:ss',
                          language: 'en',
                          pick12HourFormat: true
                      });
                  });
              &lt;/script&gt;
          &lt;/div&gt;
  
      }
      &lt;div class="form-actions"&gt;
          &lt;button type="submit" class="btn btn-primary"&gt;Save changes&lt;/button&gt;
      &lt;/div&gt;
  &lt;/fieldset&gt;
  </code></pre>
  
  <p>Now this would give me the date time picker in view but the value would not bind to my <code>DateEntered</code> value in model.</p>
  
  <p>If I wanted to do get the value from view for date time and save it may be in database,
  how would i do it? so that if i executed following command in my controller it would work.</p>
  
  <pre><code>[HttpPost]
  public ActionResult Create(fooVM user)
  {
      if (ModelState.IsValid) {
         _db.Users.Add(user);
         _db.SaveChanges();
  }
  </code></pre>
  
  <p>PS: This could be possible value in database<br>
  Name : ABC<br>
  DateEntered : 6/14/2013 9:34:23 AM</p>