开发者

Html.RouteLink href null despite route (seeming) to work

I have a route (which works):

routes.MapRoute(
    "Details", // Route name
    "{controller}/{id}", // URL with parameters
    new { controller = "Advisors", action = "Details", id = UrlParameter.Optional }, // Parameter defaults
    new { id = new GuidConstraint() } // Constraint
);

And a link:

@Html.RouteLink(@item.FullName, "Details", new { controller = "Advisors", id = item.Id })

However the link is rendering as:

<a href="">David Wick</a>

Basically my goal here is to have routes that are {controller}/{id} and the lin开发者_Python百科ks rendered are also in that format. When using Html.ActionLink() links render as {controller}/{action}/{id} and Html.RenderRoute() doesn't seem to work at all, despite the route working.

What's going on here?


I was able to correct this issue just now by changing "item.Id" to "item.Id.ToString()". Probably not the ideal solution, but good enough for me for now.


I had a similar issue (I think) and it was actually the route constraint that was failing because the IRouteConstraint was checking for

routeDirection == RouteDirection.IncomingRequest

whereas the RouteLink HTML helper will actually produce

routeDirection == RouteDirection.UrlGeneration
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜