Reputation: 850
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
Upvotes: 1
Views: 4659
Reputation: 1398
I had to use the following to access specific keys:
((System.Web.Mvc.RedirectToRouteResult)response).RouteValues["KeyName"]
Upvotes: 0
Reputation: 11
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
Upvotes: 1