Anand
Anand

Reputation: 4551

jQuery Validation Error Messages are not being displayed in jQuery Mobile Pages

I am using jQuery UnObtrusive Validation with ASP.NET MVC3: These are added scripts:-

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

I have given min-max range checks to one of the field and it generated html correctly:

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

On Load of page, I am changing the data-val-range-max attribute value by jQuery:

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

It is doing validation perfectly, on submit, if QtyToIssue is more than 11, text box turn red, and focus get set to this. Only Problem is I am not getting the error Message.

What could be the reason?

Upvotes: 0

Views: 2421

Answers (1)

Matt27
Matt27

Reputation: 325

Try adding @Html.ValidationSummary() to your view (assuming your using razor). That'll generate a div which should display the validation messages.

Upvotes: 2

Related Questions