【发布时间】:2021-03-09 17:34:34
【问题描述】:
这是我的 .cshtml 代码:
<div class="col-xs-4 col-md-2">
<div class="form-group">
<input asp-for="FileName" type="hidden" class="hdnFileName" />
<input type="file" asp-for="UploadFile" accept=".csv" />
<button id="btnUpload" class="btn btn-tertiary btnFileSelect" type="button">Browse</button>
</div>
</div>
点击上传按钮时我需要文件名的 id。
脚本:
$(".btnFileSelect").each(function () {
var btnId = $(this).attr("id");
//The below code is not working and throwing an undefined value.
//Tried .closest() which is not working either.
var fileName = $(this).prev('.hdnFileName').attr('id');
})
变量文件名显示未定义。 我要改变什么?问题是隐藏字段吗?
【问题讨论】:
-
这是您最终生成的 html 输出吗?里面没有 id 属性。如果它是从您的视图中获取的,请发布最终的 html 输出。
-
是的,现在更有意义了。
标签: javascript jquery asp.net