Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么RoutedData值总是空的?_C#_Asp.net Mvc_Web Applications - Fatal编程技术网

C# 为什么RoutedData值总是空的?

C# 为什么RoutedData值总是空的?,c#,asp.net-mvc,web-applications,C#,Asp.net Mvc,Web Applications,我正在尝试将我的url设置为 其中PDM是虚拟目录,Welcome是主页。 佛罗里达州的辩论通过了 该网址似乎是工作,除了我看不到佛罗里达正在通过 *已更新* 没有控制器。Visual Studio示例 routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { action = "Index", id= UrlParameter.Optional } );

我正在尝试将我的url设置为

其中PDM是虚拟目录,Welcome是主页。 佛罗里达州的辩论通过了

该网址似乎是工作,除了我看不到佛罗里达正在通过

*已更新*

没有控制器。Visual Studio示例

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new {  action = "Index", id= UrlParameter.Optional }
);
。。。在默认对象中未指定控制器。我使用了他们所拥有的,并对其进行了一些修改,将默认页面替换为欢迎索引和除法的instend,而不是Index。分区将始终位于url中,因此它似乎比ID更好

我试过以下方法

public static class RouteConfig {
    public static void RegisterRoutes(RouteCollection routes){
        var settings = new FriendlyUrlSettings();
        settings.AutoRedirectMode = RedirectMode.Permanent;
        routes.EnableFriendlyUrls(settings);

        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{division}",
            defaults: new {  action = "Welcome", division = UrlParameter.Optional }
        );
    }
}
2//还有许多其他方法

// this statement would be a lie there is not controller pdm is the root
routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{division}",
            defaults: new { controller="PDM"  action = "Welcome", division = UrlParameter.Optional }
        );
// the ideal way
routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{division}",
            defaults: new {  action = "Welcome", division = "Florida" }
        );
// and many more not listed
我正在尝试在prerender部分的masterpage.master上引入参数

protected override void OnPreRender(EventArgs e) {
        base.OnPreRender(e);

        RouteData rd = RouteTable.Routes.GetRouteData(new HttpContextWrapper(HttpContext.Current));

        if(rd != null){
            int i = rd.values.Count;
        }

    }

它编译吗?使用
int i=rd.values
可以将
RouteValueDictionary
分配给
int
。是的,它是编译的。我加入了if rd!=示例为null。我更新到values.count。感谢您使用
HttpContext.Current.Request.RequestContext.RouteData
?并且您可能希望为
控制器
参数提供默认值。从开始,如果没有提供任何默认值,ASP.NET可能无法构造正确的路由数据。yes Request.RequestContext.RoutedData也可以。但是,值仍然为空。我尝试传递控制器,请参见更新。