【问题标题】:How to display image when it is uploaded in ASP.NET mvc5在 ASP.NET mvc5 中上传图像时如何显示图像
【发布时间】:2019-02-20 01:03:16
【问题描述】:
上传时我不会显示或预览图片
我的代码在这里:
Html.Label("浏览文件", htmlAttributes: new { @class= "control-label col-md-2" })
</div>
<div class="col-sm-4">
@Html.Label("Logo", htmlAttributes: new { @class = "control-label col-md-2" })
<img src="FileUpload1" alt="Image" />
</div>
【问题讨论】:
标签:
asp.net-mvc
asp.net-mvc-5
【解决方案1】:
我的问题解决了
这是我的代码
@Html.Label("Browse File", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-sm-4">
<input type="file" id="FileUpload1" class="form-control" onchange="document.getElementById('logoImage').src = window.URL.createObjectURL(this.files[0])">
<pre>
`enter code here` </div>
<div class="col-sm-4">
@Html.Label("Logo Image", htmlAttributes: new { @class = "control-label col-md-2"})
<img id="logoImage" src="FileUpload1" alt="Logo Image" width="100" height="100" style="border:1px ;margin-top:20px; margin-left:120px;" />
</div
>