0

MVC4のUrlHelperクラスには以下のようなメソッドがいくつかあります

    public string Action(string actionName, object routeValues);

    public string Action(string actionName, RouteValueDictionary routeValues);

...しかし、これに対するすべてのアクションメソッド呼び出しでルート値を変更したいのでCustomUrlHelper、次のようなクラスを書きました:

public class CustomUrl : UrlHelper
{  
    public CustomUrl()
        : base(HttpContext.Current.Request.RequestContext,RouteTable.Routes){}


    public string CustomAction(string actionName, string controllerName, string areaName, object routeValues, bool generateToken)
    { 
        RouteValueDictionary rvd = new RouteValueDictionary(routeValues);
        //some changes on route value dictionary


        return Action(actionName,controllerName, rvd);
    }


}

アクション名とコントローラー名を知っていれば問題ありませんが、ベース URL とルート値の辞書だけを知っていれば、私のCustomAction方法は機能しません。

A/B/C/D とRouteValueDictionary.

ここで、完全なリンクを取得baseUrlして生成するメソッドが必要です。RouteValueDictionary

4

0 に答える 0