asp.net mvc Html.ActionLink() keeping route value I don't want

后端 未结 9 1890
我寻月下人不归
我寻月下人不归 2020-11-30 04:34

I have the following ActionLink in my view

<%= Html.ActionLink(\"LinkText\", \"Action\", \"Controller\"); %>

and it creates the follo

9条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 05:13

    Don't know why, but it didn't work for me (maybe because of Mvc2 RC). Created urlhelper method =>

     public static string
                WithoutRouteValues(this UrlHelper helper, ActionResult action,params string[] routeValues)
            {
                var rv = helper.RequestContext.RouteData.Values;
                var ignoredValues = rv.Where(x=>routeValues.Any(z => z == x.Key)).ToList();
                foreach (var ignoredValue in ignoredValues)
                    rv.Remove(ignoredValue.Key);
                var res = helper.Action(action);
                foreach (var ignoredValue in ignoredValues)
                    rv.Add(ignoredValue.Key, ignoredValue.Value);
                return res;
            }
    

提交回复
热议问题