0

我已将 asp.net mvc 与 jquery 表单验证器一起使用。

我已经在类型文件 html 上应用了 jquery 表单验证器。

当用户上传的文件超过定义的大小时,我必须在哪里停止提交?

请调查一下fiddle

在小提琴中它工作正常,但在我的代码中它没有按预期工作。

我的代码:

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.3.26/jquery.form-validator.min.js"></script>

    <h2>FileUpload</h2>

    <form action="~/home/FileUpload" id="registration-form" enctype="multipart/form-data">
        <p>
            E-mail
            <input name="email" data-validation="email">
        </p>
        <p>
            User name
            <input name="user" data-validation="length alphanumeric"
                   data-validation-length="3-12"
                   data-validation-error-msg="User name has to be an alphanumeric value (3-12 chars)">
        </p>
        <p>
            Password
            <input name="pass_confirmation" data-validation="strength"
                   data-validation-strength="2">
        </p>
        <p>
            Repeat password
            <input name="pass" data-validation="confirmation">
        </p>
        <p>
            Birth date
            <input name="birth" data-validation="birthdate"
                   data-validation-help="yyyy-mm-dd">
        </p>
        <p>
            Country
            <input name="country" id="country" data-validation="country">
        </p>
        <p>
            Profile image
            <input name="image" type="file" data-validation="mime size required"
                   data-validation-allowing="jpg, png"
                   data-validation-max-size="100kb"
                   data-validation-error-msg-required="No image selected">
        </p>
        <p>
            User Presentation (<span id="pres-max-length">100</span> characters left)
            <textarea name="presentation" id="presentation"></textarea>
        </p>
        <p>
            <input type="checkbox" data-validation="required"
                   data-validation-error-msg="You have to agree to our terms">
            I agree to the <a href="..." target="_blank">terms of service</a>
        </p>
        <p>
            <input type="submit" value="Validate">
            <input type="reset" value="Reset form">
        </p>
    </form>

    <script>

       $.validate({
    modules : 'location, date, security, file',
    onModulesLoaded : function() {
      $('#country').suggestCountry();
    }
  });

  // Restrict presentation length
  $('#presentation').restrictLength( $('#pres-max-length') );
    </script>

提交时没有验证触发没有显示错误。它在我的应用程序中提交表单而没有错误。

DOWNLOAD CODE

4

0 回答 0