简体   繁体   English

未显示部分视图加载图像

[英]Partial view load image not displayed

I implemented a PartialView Load but the (img tag) is not displayed an image. 我实现了PartialView Load,但是(img标记)未显示图像。 There was no error and the alt="IMAGE" was displayed instead. 没有错误,而是显示alt =“ IMAGE”。

Home/Index.cshtml 主页/Index.cshtml

<div id="partialviews">
</div>

<script type="text/jscript">
$(document).ready(function () {
    $("#partialviews").load('/home/GetImage');
});
</script>

Home/HomeController.cs Home / HomeController.cs

public PartialViewResult GetImage(string category)
{
    return PartialView("_ShowImage");
}

_ShowImage.cshtml _ShowImage.cshtml

<div>
    @Html.Label("Image:")
    @{ var imagePath = @"~/Images/cctv.jpg"; }
    <div>
        <img scr="@Url.Content(@imagePath)" alt="IMAGE" />
    </div>
</div>

Project directory structure 项目目录结构

Just do 做就是了

<div>
    <img scr="~/Images/cctv.jpg" alt="IMAGE" />
</div>

If this does not work, the image path is not correct. 如果这不起作用,则图像路径不正确。 And check, if the folder Images is included to your project. 并检查文件夹图像是否包含在您的项目中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM