Validating an INPUT FILE Client Without Postback Using jQuery

I want to check on the client side that the file was selected before submitting the form.

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

@using (Html.BeginForm("Upload", "Files", FormMethod.Post, new { enctype = "multipart/form-data" }))
        { 
            <input id="File" name="File" type="file" size="80" />
            <input type="submit" name="name" value="Upload" />    
        }

This form is currently performing postbacks for validation. What is going wrong?

+5
source share
3 answers

"" DOM. , , . , , 1995 1996. .

+3

@xOn , , .

, , , .

<input type="file" 
    id="myImg" 
    name="logo" 
    data-val="true" 
    data-val-required="Oops, select the logo first!"
    accept="jpg|jpeg"
    data-val-accept="Sorry, we only accept jpegs." />
+8
<input type="file" name="path" required>

html5

0

All Articles