Html.TextBoxFor set value

0 votes
asked Dec 8, 2010 by stwr

I use <input type="file" id="fileId" name="fileId"/> and <% = Html.TextBoxFor (x => x.FileName, new {@ class = "className", maxlength = 255, id = "fileName"})%> in my mvc project. I want to save in a text box the file name selected in the INPUT element. How can I do this?

1 Answer

0 votes
answered Dec 8, 2010 by darin-dimitrov

You need to use javascript to achieve this. Here's an example with jquery:

$(function() {
    $('#fileId').change(function() {
        // When the user selects a file, read the selected filename
        // and set it to the textbox
        var filename = $(this).val();
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter