Mig*_*ura 2 asp.net-mvc asp.net-web-api
我使用其模板创建了一个MVC 5站点,并添加了以下API控制器:
namespace MvcSite.Controllers {
public class TestController : ApiController {
[Route("test/send"), HttpGet]
public String Send() {
return "SENT";
}
} // TestController
} // MvcSite.Controllers
Run Code Online (Sandbox Code Playgroud)
当我访问"/ test/send"时,我按预期收到字符串"SENT"...
在Razor视图或Controller中我需要获取发送操作的URL,所以我尝试了:
var url = Url.RouteUrl(new { controller = "Test", action = "Send", HttpRoute = true });
Run Code Online (Sandbox Code Playgroud)
但是url是null ...我不知道为什么......
API路由工作正常,因此它位于路由表中...
我错过了什么?
谢谢你,米格尔
配置命名路由并使用HttpRouteUrl方法获取URL.
[Route("test/send", Name = "Send"), HttpGet]
public String Send() {
return "SENT";
}
Run Code Online (Sandbox Code Playgroud)
获取这样的URL:
var url = Url.HttpRouteUrl("Send", new {});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1823 次 |
| 最近记录: |