Reputation: 311
I have created a custom editor template for "input file" in MVC3.
I want to bind this custom made editor template to a on change event that validates the file input with Java Script. What I want to do is when browsing a input file I want to validate the file-name as soon as I have chosen the file without having to submit the page first.
So what is the best way to bind a event to a custom template?
Upvotes: 1
Views: 264
Reputation: 1039468
Well, you could add some.js
to your page in which you subscribe to the change event unobtrusively:
$(function() {
$(':file').change(function() {
var filename = $(this).val();
// perform your validations here
});
});
Upvotes: 1