开发者

ASP.NET MVC images and other static content url

I just edited my route for a user details page to look like this:

        routes.MapRoute(
            "UserDetails", // Route name
            "{controller}/{action}/{id}/{title}", // URL with parameters
            new { controller = "Users", action = 开发者_开发知识库"Details", id = UrlParameter.Optional, title = UrlParameter.Optional } // Parameter defaults
            );

Now when my url looks like this: localhost/Users/Details/1/ShawnMclean Images do not load both from the controller and the site.master. (no idea why the css and javascript had correct urls though). If the url is localhost/Users/Details/1 then everything loads fine.

My img in site.master and Details.aspx looks like this in the old url:

<img src="../../Content/Images/logo3.png" />

but when the url gets an additional parameter, the image is actually located at ../../../Content/Images/logo3.png

Is there a way to make images and other static content's url change?


Try linking your images like this:

<img src="/Content/Images/logo3.png" /> 

or if that doesn't work you could always use a helper for your links

<img src="<%= Url.Content("~/Content/Images/logo3.png") %>" />

one other way could be

<img src="@Url.Content("~/Content/Images/logo3.png")" />


You can try using a helper:

<img src='<%= Url.Content( "~/Content/Images/pic.jpg" ) %>' alt="My Image" />


You can try this,

<a href="/"><img src="<%=Url.Content("~/Content/Images/logo.png")%>" alt="logo" title="Logo" /></a> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜