title: Timespan Custom Model Binder
body: <p>I have a string type of a Time(ex: 5:00 PM) from a razor and I want to bind it to <code>timespan</code> when passing it to the controller. </p>
  
  <p>Sample Code:</p>
  
  <p>Razor:</p>
  
  <pre><code>@model Project.Models.MyModel
  
  @Html.TextBoxFor(m =&gt; m.Time, new { @class = "sTime" , @id = "txtTime" })
  
  
  &lt;script type="text/javascript"&gt;
      $(function () {   
          $(".sTime").kendoTimePicker({
              format: "h:mm tt",
              parseFormats: ["HH:mm"]
          });
          $("#txtTime").data("kendoTimePicker").value("@Model.Time");
      });
   &lt;/script&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>[HttpPost]
  public ActionResult Edit(MyModel model)
  {
      //some code here.
      return View();
  }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code> public class MyModel
   {
       public TimeSpan Time { get; set; }
   }
  </code></pre>
  
  <p>Now, the problem is that the time cannot be bind from razor to the controller. The post value is always {00:00:00}. </p>
  
  <p>How to achieve that using custom Model Binder?   </p>