0

I am getting route data value in Page_Load but I want to get this value in a class.

string id = Page.RouteData.Values["id"]; // works in Page_Load

I have tried this code in a class but it didn't work. It's returning null. I don't want to check in Page_Load() on every page. I just want to check using a function in a class if it's possible.

RouteData routeData = HttpContext.Current.Request.RequestContext.RouteData;

if(routeData != null)
{
    var id = routeData.Values["id"];
}
else
{
    // Routedata returning null;
}

Any idea?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

0 Answers0