2012-08-03 43 views
0

我使用带有剃须刀的ASP.NET MVC的日期时间选择器,当提交表单得到验证错误消息时,它不会保留我输入的值,也不会使选取器不再工作。验证错误发生后,是否可以重新使用选取器控件?当验证有错误时是否可以重用jquery 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选择器控件:

<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> 

回答

0

你可以做这样的事情,(请原谅语法错误如果有的话)

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

这您可以保留输入字段中的值。

相关问题