簡體   English   中英

Html.RouteLink href null 盡管路線(似乎)工作

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

我有一條路線(有效):

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
);

和一個鏈接:

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

但是鏈接呈現為:

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

基本上我的目標是擁有{controller}/{id}的路線,並且呈現的鏈接也是這種格式。 當使用Html.ActionLink()鏈接呈現為{controller}/{action}/{id}Html.RenderRoute()似乎根本不起作用,盡管路線工作。

這里發生了什么?

我剛才能夠通過將“item.Id”更改為“item.Id.ToString()”來糾正這個問題。 可能不是理想的解決方案,但對我來說已經足夠了。

我有一個類似的問題(我認為),實際上是路由約束失敗了,因為 IRouteConstraint 正在檢查

routeDirection == RouteDirection.IncomingRequest

而 RouteLink HTML 助手實際上會產生

routeDirection == RouteDirection.UrlGeneration

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM