0

I use datetime picker for ASP.NET MVC with razor, when submitted form got validation error message, it would not keep my entered values nor the picker not work anymore. Is it possible to reuse picker control after validation error happened?.

My view with picker:

<div class="editor-label">
    @Html.LabelFor(model => model.StartDateTime)
</div>
<div class="editor-field">
    @Html.TextBox("Start", null, new { @class = "date" })
    @Html.ValidationMessageFor(model => model.StartDateTime)
</div>

jquery picker control:

<script src="/Scripts/mobiscroll-2.0.1.custom.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
    var now = new Date();

    $('#Start').scroller({
        preset: 'datetime',
        minDate: new Date(now.getFullYear(), now.getMonth(), now.getDate()),
        theme: 'ios',
        display: 'modal',
        mode: 'scroller'
    });</script>
San
  • 1,104
  • 3
  • 17
  • 31

1 Answers1

0

you could do something like this, (please excuse syntax error if any)

public ActionResult MyView(MyModel model)
{
   if(!ModelState.IsValid())
   { 
     return View("BackToForm", model)
   }
}

this way you could preserve the values in your input fields.

Yasser Shaikh
  • 46,934
  • 46
  • 204
  • 281