Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html.TextBoxFor set value

Tags:

asp.net-mvc

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?

like image 784
Stwr Avatar asked Feb 12 '26 16:02

Stwr


1 Answers

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();
        $('#fileName').val(filename);
    });
});
like image 91
Darin Dimitrov Avatar answered Feb 15 '26 10:02

Darin Dimitrov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!