user473104
user473104

Reputation: 311

Custom editor template with events MVC3

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

Answers (1)

Darin Dimitrov
Darin Dimitrov

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

Related Questions