我已经习惯了使用类似下面生成MVC控制器动作中路由指向其他控制器操作:
public class ApplicationController : Controller
{
public ActionResult Index( )
{
var url = Url.RouteUrl("routename",
new { controller = "Application", Action = "Index2" , other="other" });
}
public ActionResult Index2( string other)
{
}
}
但我也需要能够产生从内部的WebAPI过的网址MVC控制器动作,我将如何去这样做呢?
人们似乎对APIController一个UrlHelper财产,但我不能找到如何利用这一点,并没有能够找出自己的任何实例。
更新:我想生成一个URL的原因是,这个特殊的WebAPI方法将其提供与链接收件人引导用户回到网站的相应部分的电子邮件。 我显然想从这个硬编码离开,因为它不会对不同的部署工作,另外,如果我开始改变路由此链接将被打破。 是否有这样做的更好的方法?