ASP.NET MVC - 路由问题
这是有问题的 URL,它导致我的所有图像损坏。
http://www.foo.com/payment/receipt/stapia.gutierrez/201110040000034
我的所有内容(图像和其他内容)都在我的 _Layout.cshtml 文件中声明。我相信这是我的路由问题。
以下是我的 Global.asax 路由区域的相关部分:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"AllPayments",
"payment/receipt/{username}",
new { controller = "Payment", action = "AllPayments" }
);
routes.MapRoute(
"IndividualPayment",
"payment/receipt/{username}/{id}",
new { controller = "Payment", action = "SinglePayment" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
这是我的图像在 _Layout.cshtml 文件中声明的方式:
<img src="../../Content/SiteImages/banner1.jpg" width="200" height="200" />
<img src="../../Content/SiteImages/banner2.jpg" width="200" height="200" />
<img src="../../Content/SiteImages/banner3.jpg" width="200" height="200" />
通常我的图像将 src
到
www.foo.com/Content /SiteImages/logo.png
,
在此特定视图中,它们更改为
www.foo.com/payment/Content/SiteImages/logo.png
如何解决此问题?是什么导致我的图像 src 在这个特定视图中发生变化?
This is the URL in question, that causes all of my images to break.
http://www.foo.com/payment/receipt/stapia.gutierrez/201110040000034
All of my content (images and whatnot) is declared in my _Layout.cshtml file. I believe this is an issue with my routing.
Here are the relevant parts of my Global.asax routing area:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"AllPayments",
"payment/receipt/{username}",
new { controller = "Payment", action = "AllPayments" }
);
routes.MapRoute(
"IndividualPayment",
"payment/receipt/{username}/{id}",
new { controller = "Payment", action = "SinglePayment" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
This how my images are declared in my _Layout.cshtml file:
<img src="../../Content/SiteImages/banner1.jpg" width="200" height="200" />
<img src="../../Content/SiteImages/banner2.jpg" width="200" height="200" />
<img src="../../Content/SiteImages/banner3.jpg" width="200" height="200" />
Where normally my images would src
to
www.foo.com/Content/SiteImages/logo.png
,
in this particular view, they are changed to
www.foo.com/payment/Content/SiteImages/logo.png
How can I fix this issue? What is causing my images src to change in this particular view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您正在查看特定付款,因此您会更深入地了解该网址。
地方
在 AllPayments 页面上可以使用的
,您需要在个人付款页面上使用。
Since you are viewing a specific payment, you are one step deeper into the url.
Where
would work on the AllPayments page, you need
on the individual payment page.