2011-12-09 243 views
0

我使用jQuery不显眼的验证与ASP.NET MVC3没有被显示在jQuery Mobile的网页: 这些被添加的脚本: -jQuery验证错误消息

<link rel="stylesheet" href="http://code.jquery.com/mobile/latest/jquery.mobile.min.css" /> 
    <script src="http://code.jquery.com/jquery-1.6.1.min.js"></script> 
    <script type="text/javascript"> 
     $('div').live('pageshow', function (event) { 
      jQuery.validator.unobtrusive.parse(".ui-page-active form"); 
     }); 
    </script> 
    <script src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js" type="text/javascript"></script> 

    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> 

我已经给了最小 - 最大范围检查领域之一,它生成的html正确:

<div class="display-label"> 
      <label for="QtyToIssue">Qty to Issue</label> 
     </div> 
     <div class="display-field"> 
      <input class="text-box single-line" data-val="true" data-val-number="The field Qty to Issue must be a number." data-val-range="The field Qty to Issue must be between 0 and 1.79769313486232E+308." data-val-range-max="1.79769313486232E+308" data-val-range-min="0" data-val-required="The Qty to Issue field is required." id="QtyToIssue" name="QtyToIssue" type="number" value="0" /> 
     </div> 

在页面加载,我改变了数据-VAL-范围-max属性值的jQuery:

<script type="text/javascript"> 
     $(function() { 
     $('#QtyToIssue').attr('data-val-range-max', 11.000000); 
     }); 
    </script> 

它正在完美验证,在提交时,如果QtyToIssue大于11,文本框变为红色,焦点设置为此。 唯一问题是我没有收到错误消息。

可能是什么原因?

回答

2

尝试将@Html.ValidationSummary()添加到您的视图(假设您使用剃须刀)。这将生成一个应显示验证消息的div。

+0

感谢@using(Html.BeginForm()) {Html.ValidationSummary(false)我得到我的属性特定的错误消息立即,我想要的。 –