我正在尝试在ASP.NET MVC中做一些简单的事情:
RouteValuesDictionary routeValues = GetMyRouteData(); var url = new UrlHelper(Html.ViewContext.RequestContext); return url.RouteUrl(routeValues);
问题在于,无论我做什么,url都包含来自当前请求上下文的路由数据.我想基于GetMyRouteData()的路由值生成一个URL.
谢谢
解决方法
The problem is that no matter what I do,the url includes route data@H_301_14@ from the current request context
这是设计的.您必须显式设置原始请求中存在的路由值,并且您不希望在生成的URL中为null:
var routeValues = GetMyRouteData(); // remove values that you want to exclude from the resulting url // by setting their values to null routeValues["id"] = null; var url = new UrlHelper(Html.ViewContext.RequestContext); return url.RouteUrl(routeValues);