ASP.NET MVC - 路由问题

发布于 2024-12-08 07:28:34 字数 1462 浏览 0 评论 0原文

这是有问题的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悍妇囚夫 2024-12-15 07:28:34

由于您正在查看特定付款,因此您会更深入地了解该网址。

地方

<img src="../../Content/SiteImages/banner1.jpg" width="200" height="200" />

在 AllPayments 页面上可以使用的

<img src="../../../Content/SiteImages/banner1.jpg" width="200" height="200" />

,您需要在个人付款页面上使用。

Since you are viewing a specific payment, you are one step deeper into the url.

Where

<img src="../../Content/SiteImages/banner1.jpg" width="200" height="200" />

would work on the AllPayments page, you need

<img src="../../../Content/SiteImages/banner1.jpg" width="200" height="200" />

on the individual payment page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文