简体   繁体   中英

how can i get RouteValueDictionary values from Page.RouteData.DataTokens

how can i get RouteValueDictionary values from Page.RouteData.DataTokens

My Code:

routes.MapPageRoute("NewsDetails", "NewsDetails/{id}/{title}",
                    "~/NewsDetails.aspx", false,
                     new RouteValueDictionary { { "id", 0 },
                     { "title", string.Empty } });

i want get id and title because Page.RouteData.Values does not working

在此处输入图片说明

thanks

I had this problem too; Page.RouteData.Values was not returning any values but I could see the passed value under DataTokens .

It turns out that routes.EnableFriendlyUrls was messing with my route mapping, So after I read this article by Hanselman --> and used Request.GetFriendlyUrlSegments() to get the values.

It worked but I didn't want to have to iterate through all the values to assign them (as suggested in the article). So, instead of using Request.GetFriendlyUrlSegments() , I changed the order of my route mappings (under RouteConfig.cs ) so that routes.EnableFriendlyUrls(settings); is registered after all the other routes have been registered.

It was only after I changed the ordering of the routes that I got my values from Page.RouteData.Values

尝试使用Page.RouteData.Values代替。

我必须使用以下内容来访问特定的键:

((System.Web.Mvc.RedirectToRouteResult)response).RouteValues["KeyName"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM