我正在一个教程的帮助下使用此代码,但仍然无法上传图片,我的意思是图片未显示,请有人对此提供帮助
这是我使用的代码:-
<div class="col-md-6">
<div class="form-group">
@Html.LabelFor(model => model.ImgPath, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<img src="@Url.Content(Model.ImgPath)" style="margin:10px" height="200" width="200" id="imagePreview" />
<input type="file" name="ImageUpload" accept="image/jpeg, image/png" onchange="ShowImagePreview(this, document.getElementById('imagePreview')" />
</div>
</div>
</div>
答案 0 :(得分:-1)
如果您的图片没有上传,我认为您应该检查表格标签并使其类似
<form method="post" enctype="multipart/form-data">
//your image upload
<input type="file" name="ImageUpload" accept="image/jpeg, image/png" />
</form>
然后您可以使用
Request.Files
并访问所有发送的文件,或者如果您希望将其强烈嵌入使用
//this for Asp.Net Core
public IActionResult(IFormFile ImageUpload)
{
//Everything here
}
//Or this for Asp.Net
public ActionResult(HttpPostedFileBase ImageUpload)
{
//Everything else here
}
阅读这篇stackoverflow帖子以了解它