Creating a URL inside a controller in ASP.NET MVC

Is there a way to generate the url inside the controller? I want to do the following inside a controller instead of a view.

<% =Url.Action("Validate", "Home", New With {.ValidID = ID})%>

+4
source share
2 answers

Just remove the "Bee-stings."

Sort of:

 url = Url.Action("Validate", "Home", New With {.ValidID = ID}) 
+6
source

Yes, as long as your controller inherits Controller (which it needs to work as an MVC controller), you can use the same syntax without <% =%>.

 Dim url = Url.Action("myAction", "myController", New With { ... }) 

alternatively, if you reference the MVCContrib DLL, you will have access to strongly typed helpers and you can do something like:

 Dim url = Url.Action(Of myController)(function(a) a.myAction(ID)) 

my VB coding days are dated, so forgive me if the syntax is a bit fake

+2
source

Source: https://habr.com/ru/post/1300072/


All Articles