ASP.NET MVC公共替代UrlHelper.GenerateUrl [英] ASP.NET MVC public alternative to UrlHelper.GenerateUrl

查看:712
本文介绍了ASP.NET MVC公共替代UrlHelper.GenerateUrl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要嵌入我的网页链接到一个控制器动作,所以我可以从JavaScript中使用它。类似

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'

现在我很高兴地硬code,但如果有,我可以用它来创建网址的方法,将是非常好的。该AjaxHelper / HtmlExtensions包含的方法来创建超链接(.ActionLink(...)等),但如果你看看他们的胆量,他们依靠一个名为UrlHelper.GenerateUrl(方法)来解决控制器和行动统​​一到一个URL。这是内部的,所以我不能真正得到这个。

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?

推荐答案

你试过东西沿着这些路线?

Have you tried something along these lines?

var pollAction = '<%=Url.Action("CheckStatus", "MyController") %>';

这篇关于ASP.NET MVC公共替代UrlHelper.GenerateUrl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆