我在我的mvc项目中使用<input type="file" id="fileId" name="fileId"/>和
<% = Html.TextBoxFor (x => x.FileName, new {@ class = "className", maxlength = 255, id = "fileName"})%>.我想在文本框中保存在INPUT元素中选择的文件名.我怎样才能做到这一点?
你需要使用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);
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8062 次 |
| 最近记录: |