Asp.net mvc 从WebAPI生成MVC控制器操作的路由Url
我习惯于在MVC控制器操作中使用类似于以下内容的内容生成指向其他控制器操作的路由URL:Asp.net mvc 从WebAPI生成MVC控制器操作的路由Url,asp.net-mvc,asp.net-mvc-4,asp.net-web-api,asp.net-mvc-routing,urlhelper,Asp.net Mvc,Asp.net Mvc 4,Asp.net Web Api,Asp.net Mvc Routing,Urlhelper,我习惯于在MVC控制器操作中使用类似于以下内容的内容生成指向其他控制器操作的路由URL: public class ApplicationController : Controller { public ActionResult Index( ) { var url = Url.RouteUrl("routename", new { controller = "Application", Action = "Index2" , other="
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控制器操作的URL,我该如何做呢
ApicController上似乎有一个UrlHelper属性,但我找不到任何关于如何使用该属性的示例,我自己也没有弄清楚
更新:
我之所以尝试生成url,是因为这个特定的webapi方法会发送一封电子邮件,为收件人提供一个链接,将用户引导回站点的适当部分。我显然不想硬编码,因为它不适用于不同的部署,而且如果我开始更改路由,此链接将被中断。有更好的方法吗?您也可以在web API UrlHelper中使用MVC路由名称。例如
Url.Link("Default", new { Controller = "Account", Action = "Login" });
或
@你找错人了。看看http而不是mvc。。如果您使用的是属性路由,请命名路由。我们确定这是可能的吗?我收到“名为“…”的路由”异常,此问题表明无法执行此操作:
Url.Route("Default", new { Controller = "Account", Action = "Login" });