Javascript 更改添加新列时的文本框值
我的MVC视图中有以下ImageUpload文本框字段Javascript 更改添加新列时的文本框值,javascript,c#,jquery,asp.net-mvc,Javascript,C#,Jquery,Asp.net Mvc,我的MVC视图中有以下ImageUpload文本框字段 for (int i = 0; i < Model.Count; i++) { @Html.TextBox("file", new { type = "file", @class = "form-control" }) } for(int i=0;i0) { @{ @DisplayFor(m=>imagePath) } } } } 这是经过测试的示例,它在新列中显示文件名,出于安全原因,浏览器将无法访问文件路径详细信息,因此
for (int i = 0; i < Model.Count; i++)
{
@Html.TextBox("file", new { type = "file", @class = "form-control" })
}
for(int i=0;i
现在,当用户选择图像时,我想再添加一列来显示图像的路径
我尝试了以下代码,但不起作用
<script type="text/javascript">
$(function ()
{
$("#file").on("input", function ()
{ // trigger when you input to textbox
if ($(this).val().length > 0)
{
<td>
@{
@Html.DisplayFor(m => imagePath)
}
</td>
}
}
}
</script>
$(函数()
{
$(“#文件”)。关于(“输入”,函数()
{//当您输入文本框时触发
如果($(this.val().length>0)
{
@{
@DisplayFor(m=>imagePath)
}
}
}
}
这是经过测试的示例,它在新列中显示文件名,出于安全原因,浏览器将无法访问文件路径详细信息,因此您将无法显示路径(至少我知道这是我知道的,如果您发现了什么,请随意附加链接)
@for(int i=0;i<table>
<tbody>
@for (int i = 0; i < Model.Count; i++)
{
<tr>
<td>
@*Second parameter is the value field for texbox which is missing in oyur code*@
@Html.TextBox("file", i, new { @type = "file", @class = "form-control" })
</td>
</tr>
}
</tbody>
</table>
<script>
$(".form-control").on("change", function (event) {
var fileName = event.target.files[0].name;
$(this).parent().append('<td>' + fileName + '</td');
});
</script>