Search code examples
asp.net-coreasp.net-mvc-5asp.net-mvc-routing

How can i get page path in asp.net mvc core


Unable to access Url.ActionContext.View.Path I have to show on particual Path/View/Action Call

How can i get path in ASP.Net Core MVC in quick watcher Url.ActionContext.View.Path it shows value but can't use gives error


Solution

  • found solution for asp.net core MVC //for View
    string viewname= ((object[])((Microsoft.AspNetCore.Mvc.Routing.UrlHelper)Url).ActionContext.RouteData.Values.Values)[1].ToString(); //for controller
    string controllername = ((object[])((Microsoft.AspNetCore.Mvc.Routing.UrlHelper)Url).ActionContext.RouteData.Values.Values)[0].ToString();