据我所知,我已正确编码,但我仍然收到404错误。
我认为我的webconfig可能有问题,所以我添加了以下mimeType ...
<staticContent>
<remove fileExtension=".svg" />
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
</staticContent>
,但我仍然收到所有.svg文件的错误。
无法加载资源:服务器响应状态为404(未找到)
我在局部视图中有以下代码,这简单地创建了没有错误的列表,但文件路径错误仍然显示。
@{
string[,] fruits = new string[1, 3] { { "Kiwi", "kiwi.svg", "bg-kiwi" } };
string[,] meats = new string[1, 3] { { "Steak", "steak.svg", "bg-steak" } };
string[,] candy = new string[1, 3] { { "Candy", "candy.svg", "bg-candy" } };
}
@{
for (int i = 0; i < fruits.GetLength(0); i++)
{
<div class="item">
<img class="@fruits[i, 2]" title="fruits[i, 0]" src="~/Images/@fruits[i,1]" />
</div>
}
for (int i = 0; i < meats.GetLength(0); i++)
{
<div class="item">
<img class="@meats[i, 2]" title="@meats[i, 0]" src="~/Images/@meats[i,1]" />
</div>
}
for (int i = 0; i < candy.GetLength(0); i++)
{
<div class="item">
<img class="@candy[i, 2]" title="@candy[i, 0]" src="~/Images/@candy[i,1]" />
</div>
}
}
<div class="masonry" style="position: relative; height: 204px;">
<div class="item" style="position: absolute; left: 0px; top: 0px;">
<img class="bg-kiwi" title="kiwi" src="/Images/kiwi.svg">
</div>
<div class="item" style="position: absolute; left: 210px; top: 0px;">
<img class="bg-steak" title="steak" src="/Images/steak.svg">
</div>
<div class="item" style="position: absolute; left: 420px; top: 0px;">
<img class="bg-candy" title="candy" src="/Images/candy.svg">
</div>
</div>
答案 0 :(得分:1)
您应该尝试使用mvc解析路径:
src="@Url.Content("~/Images/@meats[i,1]")"
还要确保路由正确处理您的图像请求。例如,您可能希望忽略路由表中的图像请求:
routes.IgnoreRoute("Images/{*pathInfo}");