Reputation: 8659
I am pretty new to MVC5 and I am trying to have a Content folder locally under one of my Areas. 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 (i.e. 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.
How can I find my resources under Content?
Upvotes: 1
Views: 772
Reputation: 8659
The reason I received a 404 was the BlockViewHandler in the Area1 web.config
. I created a new web.config and placed in my Static
folder to solve the problem.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler" />
</handlers>
</system.webServer>
</configuration>
Upvotes: 1