How can you access RouteData from the code-behind?

You could also use the following:

//using System.Web;
HttpContext.Current.Request.RequestContext.RouteData

You can use the following:

RouteTable.Routes.GetRouteData(new HttpContextWrapper(HttpContext.Current));

  [HttpGet]
  [Route("{countryname}/getcode/")]
  public string CountryPhonecode()
  {
     // Get routdata by key, in our case it is countryname
     var countryName = Request.GetRouteData().Values["countryname"].ToString();

     // your method
     return GetCountryCodeByName(string countryName);
  }