如何在MVC应用程序中显示图像

本文关键字:显示 显示图 图像 应用程序 MVC | 更新日期: 2023-09-27 18:01:04

我在应用程序的View部分的文件夹中有一些图像。我想在视图窗体中显示这些图像,但无法显示这些图像。网址可能有问题。

这是我对的看法

<html xmlns="http://www.w3.org/1999/xhtml">`enter code here`
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Ceylon Brokers</title>
        @section styles{
    <link rel="Stylesheet" href="@Href("~/css/styles.css")" />
}
    </head>
    <body>
        <div id="background">
            <div id="footer"><img alt="social_links" usemap="#social" src=@Url.Content("~/images/footer.png")>
            <map id="social" name="social">
            <area shape="circle" coords="79,122.5,35" href="https://www.facebook.com/ceylonbrokers?fref=ts" alt="social_links"/>
            <area shape="circle" coords="160,123,34.5" href="" alt="social_links"/>
            <area shape="circle" coords="245,122.5,35" href="http://www.linkedin.com" alt="social_links"/>
            </map>
            </div>
            <div id="whyusbg"><img src="~/images/whyusbg.png"></div>
            <div id="header"><img alt="page_titles" usemap="#pages" src="../images/header.png">
            <map id="pages" name="pages">
            <area shape="rect" coords="430,90,520,120" href="index.html" alt="page_titles"/>
            <area shape="rect" coords="540,90,690,120" href="about.html" alt="page_titles"/>
            <area shape="rect" coords="720,90,880,120" href="" alt="page_titles"/>
            <area shape="rect" coords="910,90,1110,120" href="" alt="page_titles"/>
            <area shape="rect" coords="1140,90,1340,120" href="" alt="page_titles"/>
            <area shape="rect" coords="1370,90,1550,120" href="" alt="page_titles"/>
            </map>
            </div>
        </div>
 </body>
 </htm

以下图像不可用。

http://localhost:50242/images/whyusbg.png 404 (Not Found)
http://localhost:50242/images/footer.png 404 (Not Found)
http://localhost:50242/images/header.png 404 (Not Found)

如何将我的图像文件链接到表单?

提前感谢

如何在MVC应用程序中显示图像

图像不应该真正位于应用程序的View文件夹中。通常,你会在MVC站点的根目录上有一个Content文件夹,然后我亲自把我的images文件夹放在那里。然后,要访问任何图像,你会说:

@Url.Content("~/content/images/my-image.jpg")

如果你想把图片文件夹放在网站的根目录上,只需把images放在与当前view文件夹相同的文件夹级别上,然后访问:

@Url.Content("~/images/my-image.jpg")