2010-12-08 64 views
2

我在我的mvc項目中使用<input type="file" id="fileId" name="fileId"/><% = Html.TextBoxFor (x => x.FileName, new {@ class = "className", maxlength = 255, id = "fileName"})%>。我想在文本框中保存在INPUT元素中選擇的文件名。我怎樣才能做到這一點?Html.TextBoxFor設定值

回答

4

您需要使用javascript來實現此目的。這裏有一個與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); 
    }); 
}); 
+0

謝謝,它的工作原理 – Stwr 2010-12-08 08:08:32