I use the form to upload a file. I want only PDF files loaded. This is my code:
An input field that allows the user to select a file:
@Html.FileBox(m => m.FileName, new { id = "FileName", accept = "application/pdf" })
and place to display error messages:
@Html.ValidationMessageFor(m=>m.FileName)
Code generated for input field:
<input id="FileName" type="file" name="FileName" data-val-required="The File Name field is required." data-val-length-max="512" data-val-length="The field File Name must be a string with a maximum length of 512." data-val="true" accept="application/pdf">
Now, even if I select a PDF file, I get an error message Please enter a value with a valid extension.
I use MVC 3 and unobstrusive jquery to validate the form.
escist
source share