4

RouteValueDictionary を使用して RouteValues を ActionLink に渡しています。

私がコーディングした場合:

<%:Html.ActionLink(SharedResources.Shared_Pagination_First, Model.ActionToExecute, Model.ControllerToExecute, Model.FirstRouteValues, null)%>

リンクの結果はOKです:

SearchArticles?refSearch=2&exact=False&manufacturerId=5&modelId=3485&engineId=-1&vehicleTypeId=5313&familyId=100032&page=0

しかし、私がコーディングした場合:

<%: Html.ActionLink(SharedResources.Shared_Pagination_First, Model.ActionToExecute, Model.ControllerToExecute, Model.FirstRouteValues, new { @title = string.Format(SharedResources.Shared_Pagination_LinkTitle, 0) })%>

リンクの結果は次のとおりです。

SearchArticles?Count=10&Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&Values=System.Collections.Generic.Dictionary%602%2BValueCollection%5BSystem.String%2CSystem.Object%5D

どうしたの?唯一の違いは、最後に htmlAttributes を使用していることです

4

2 に答える 2

7

ActionLink ヘルパーの間違ったオーバーロードを使用しています。および匿名オブジェクトとしてrouteValues受け取るオーバーロードはありません。したがって、が a の場合、最後の引数も a または単純であり、無名オブジェクトではない必要があります。そのように:RouteValueDictionaryhtmlAttributesModel.FirstRouteValuesRouteValueDictionaryRouteValueDictionaryIDictionary<string,object>

<%= Html.ActionLink(
    SharedResources.Shared_Pagination_First, 
    Model.ActionToExecute, 
    Model.ControllerToExecute, 
    Model.FirstRouteValues, 
    new RouteValueDictionary(
        new { 
            title = string.Format(SharedResources.Shared_Pagination_LinkTitle, 0) 
        }
    )
) %>

また

<%=Html.ActionLink(
SharedResources.Shared_Pagination_First, 
Model.ActionToExecute, 
Model.ControllerToExecute, 
Model.FirstRouteValues, 
new Dictionary<string, object> { { "title", somevalue  } })%>
于 2012-07-27T10:03:39.080 に答える
1

パラメータに一致するオーバーロードはありません。 objectroutehtml またはRouteValueDictinaryandのいずれかを使用する必要がありIDictionary<string,object>ます。

そのようです:

Html.ActionLink(SharedResources.Shared_Pagination_First, Model.ActionToExecute, Model.ControllerToExecute, Model.FirstRouteValues, new Dictionary<string.object> { { "title", somevalue  } })
于 2012-07-27T10:05:44.043 に答える