title: How do I force the value in a textbox in a form to a default value when the value entered is invalid?
body: <p>For example, in the controller view setup below everything works fine except that when I type something ridiculous in the textbox like 99/12/2014 it doesn't set it to the default 29/12/2014 when I press the submit button but it does set it to the default when I press the action link.</p>
  
  <p>I have removed all other code because it is not relevant to the problem.</p>
  
  <p>I want the textbox value to correct itself when I press the submit button if the value entered is not a valid date.</p>
  
  <p>Controller:</p>
  
  <pre><code>public class HomeController : Controller
      {
          public ActionResult Index(string myDate = null)
          {
              DateTime _myDate;
              if (!DateTime.TryParse(myDate, out _myDate))
              {
                  _myDate = new DateTime(2013, 12, 29);
              }
  
              ViewBag.myDate = myDate = _myDate.ToString();
  
              return View();
          }
     }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>@using (Html.BeginForm("Index", "Home", FormMethod.Get))
  {   
      @Html.TextBox("myDate");
  
      &lt;input type="submit" value="Submit" /&gt;
  }
  @Html.ActionLink("Select", "Index", new { myDate = ViewBag.MyDate })
  </code></pre>