File input filters in mvc4 or html 5?

I know that we can use filter types in HTML 5 with accept attribute <input accept="audio/*|video/*|image/*|MIME_type">

But all this shows the "All Files" options. I want to strictly adhere to certain types of files in the form of "* .pdf, All types of office words, images, excel".

How can we do this?

My code for example

  @Html.TextBoxFor(m => m.Attachment, new { @class = "form-control", type = "file" })
+3
source share
1 answer

You simply replace your accept (s) with the full mime type in your application / pdf application, and not the * wildcard.

@Html.TextBoxFor(m => m.Attachment, new { @class = "form-control", type = "file", accept="application/pdf" })

You can separate multiple mime types with a comma if you want the PDF and the word in the same download control to be done like this:

@Html.TextBoxFor(m => m.Attachment, new { @class = "form-control", type = "file", accept="application/pdf, application/msword" })

Update

mime ( )

private List<string> mimeTypes = new List<string> {
        "application/pdf", 
        "application/msword"
    };

mime , :

model.MimeTypes = string.Join(", ", mimeTypes);

:

@Html.TextBoxFor(m => m.Attachment, new { @class = "form-control", type = "file", accept=Model.MimeTypes })
+3

All Articles