Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC public alternative to UrlHelper.GenerateUrl

Tags:

c#

asp.net-mvc

I want to embed a link to a controller action in my page so I can use it from javascript. Something like

var pollAction = '/Mycontroller/CheckStatus'

Now I am happy to hardcode it, but it would be really nice if there were a method I could use to create the URL. The AjaxHelper/HtmlExtensions contain methods to create hyperlinks (.ActionLink(...) and so on), but if you look into the guts of them, they rely on a method called UrlHelper.GenerateUrl() to resolve a controller and action into a url. This is internal so I can't really get at this.

Anyone found a good method in the framework to do this? Or must I roll my own?

like image 301
Jennifer Avatar asked Dec 10 '08 11:12

Jennifer


1 Answers

Have you tried something along these lines?

var pollAction = '<%=Url.Action("CheckStatus", "MyController") %>';
like image 105
mapache Avatar answered Sep 21 '22 18:09

mapache