Apsed1976
Apsed1976

Reputation: 31

How to get url of a view by its name in ASP MVC?

Let's say there's a view with a name MyView.

How can I get a url if this view by its name?

Upvotes: 0

Views: 1912

Answers (1)

Yeldar Kurmangaliyev
Yeldar Kurmangaliyev

Reputation: 34189

View cannot have an URL.
An action which returns this view as a result can have an URL.

You can simply acquire action's URL using UrlHelper, it is available both in Controller class or CSHTML view file:

Url.Action("MyAction") // MyAction action of default controller
Url.Action("MyAction", "MyController") // MyAction action of specified MyController

Upvotes: 2

Related Questions