Reputation: 707
I create a helper and i want to get view's path in this helper code, How can i do that?
I try code below. It will use view that return from action. So If i use this helper in partial view it will get parent view name instead.
RazorView view = helper.ViewContext.View as RazorView;
viewPath = view.ViewPath;
Thank you in advance.
Upvotes: 2
Views: 5107
Reputation:
You can retrieve the path of the view or partial view using
string path = (helper.ViewDataContainer as WebPageBase).VirtualPath;
This will return something like ~/Views/Home/MyPartial.cshtml
Upvotes: 4