Reputation: 1740
I have this code in ASP.NET MVC 3 and now, I'm converting it to ASP.NET Core MVC.
In the class file, I'm reading RouteData
values as shown here:
public class Utilities
{
public Utilities()
{
_urlWord = Convert.ToString(HttpContext.Current.Request.RequestContext.RouteData.Values["url"]);
}
}
How to convert this into ASP.NET Core MVC code? How to read the RouteData
values in ASP.NET Core MVC?
Upvotes: 1
Views: 426
Reputation: 43959
in net core you can do the same using this
var id = HttpContext.Request.RouteValues["id"];
or using all route values
var values = HttpContext.Request.RouteValues
.Select(v => new { Key = v.Key, Value = v.Value }).ToList();
var idValue = values.FirstOrDefault(v=> v.Key=="id");
var id = idValue.Value;
Upvotes: 2