[英]Path to image under MVC5 Area
I am pretty new to MVC5 and I am trying to have a Content folder locally under one of my Areas. 我是MVC5的新手,我正在尝试在我的一个区域下本地创建一个Content文件夹。 Unfortunately I cannot seem to get the image to render in the output since the path becomes incorrect(?) and I can´t figure out how to correctly reference it.
不幸的是,由于路径不正确(?),我似乎无法在输出中呈现图像,而且我无法弄清楚如何正确引用它。
In my solution I the following: 在我的解决方案中,我执行以下操作:
ProjectX
Areas
Area1
Controller
Area1DefaultController
Content
Images
image1.png
Views
View1.cshtml
In my View i use this: 在我看来,我使用这个:
@Url.Content("~/Areas/Area1/Content/Images/image1.png")
I have also tried.. 我也尝试过..
@Url.Content("~/Content/Images/image1.png")
@Url.Content("/Content/Images/image1.png")
@Url.Content("Content/Images/image1.png")
..and the result in all cases are broken images (ie the path is incorrect). ..并且在所有情况下结果都是损坏的图像(即路径不正确)。 I guess the routing somehow prevents the image from being retrieved but I can´t figure out how to fix the problem.
我想路由以某种方式阻止了图像的检索,但是我不知道如何解决该问题。
This is my area registration: 这是我的地区注册:
public class Area1Registration : AreaRegistration
{
public override string AreaName
{
get { return "Area1"; }
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Area_default",
"Area/{action}/{id}",
new { controller = "Area1Default", action = "Index", id = UrlParameter.Optional }
);
}
}
UPDATE : ReSharper is able to resolve the path in the markup. 更新 :ReSharper能够解析标记中的路径。
How can I find my resources under Content? 如何在“内容”下找到我的资源?
The reason I received a 404 was the BlockViewHandler in the Area1 web.config
. 我收到404的原因是Area1
web.config
的BlockViewHandler。 I created a new web.config and placed in my Static
folder to solve the problem. 我创建了一个新的web.config并将其放在“
Static
文件夹中以解决该问题。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler" />
</handlers>
</system.webServer>
</configuration>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.