这些加上我尝试过的其他一些组合都不起作用
<li><a href="@Url.RouteUrl("DefaultApi",new {area=string.Empty,httproute = string.Empty, controller = "corpuserrequest", action="Get"})">CorpUser</a></li>
<li><a href="@Url.Action("Get","CorpUserRequest",new {area=string.Empty,httproute ="", controller = "CorpUserRequest", action="Get"})">CorpUser</a></li>
这是我的 api 配置路由表:
//https://stackoverflow.com/questions/11407267/multiple-httppost-method-in-mvc4-web-api-controller
config.Routes.MapHttpRoute(
name: "ApiReq",
routeTemplate: "webapi/{controller}/{action}",
defaults: null,
constraints: new { action = "Req" }
);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional },
constraints: new
{
id = @"^\d*$",// Only integers
action = "^(?![rR]eq)$" //anything except req or Req
}
);
为什么路由不起作用?RouteUrl返回空字符串或null,Action返回
<a href="http://localhost:11601/CorpUserRequest/Get">
而不是实际的网址应该是什么http://localhost:11601/api/CorpUserRequest