【问题标题】:Asp.Net Mvc RouteData is filled with wrong parametersAsp.Net Mvc RouteData 填充了错误的参数
【发布时间】:2009-06-15 07:57:16
【问题描述】:
routes .Add ("Detail",
                new Route ("{maincategory}/{category}",
                          new RouteValueDictionary (new { controller = "Category", action = "Detail"}),
                          new RouteValueDictionary (new { category = new FromValuesListConstraint ("")}),
                          new MyRouteHandler ()));

        routes.Add("Category",
                new Route("{category}",
                          new RouteValueDictionary(new { controller = "Category", action = "Index", category = "" }),
                          new RouteValueDictionary(new { category = new FromValuesListConstraint("") }),
                          new MyRouteHandler()));

        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults

        );

我的路线是这样的。但是当我运行网站时,会显示主页。在显示主页后,会发生一些事情并再次进行新的新任务(我不知道为什么)我覆盖了 MvcRouteHandler 并在其中放置了一个断点。

public class MyRouteHandler : MvcRouteHandler
{
    protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        var url = HttpContext.Current.Request.RawUrl;
        var route = requestContext.RouteData;  
        return new MvcHandler(requestContext);
    }
}

url 变量是 /Content/Divider.gif。因此,在显示主页后,应用程序会出错。作为一个新手 mvc 用户,我尝试了一切来理解这个问题。但我找不到任何东西。

谢谢!

【问题讨论】:

  • 您能否在解决方案范围内搜索“Divider.gif”一词并查看您在哪里使用它?是否在母版页中,查看?
  • divider.gif 在 Css 文件中。背景:透明 url('divider.gif') 但是我的解决方案中没有这样的文件。我正在使用我朋友网站上的旧 CSS

标签: asp.net-mvc routing


【解决方案1】:

您的网站上是否存在 /Content/Divider.gif 文件?

它可能正试图将其作为路由执行,因为该文件不存在,这就是您的问题的根源。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-17
    • 1970-01-01
    相关资源
    最近更新 更多