【发布时间】:2012-08-08 16:04:32
【问题描述】:
就在我认为我已经确定了路由时,它并没有按照我认为的方式工作。我正在使用 ASP.Net MVC 4 RC。这是我的 RouteConfig:
routes.MapRoute
(
"TwoIntegers",
"{controller}/{action}/{id1}/{id2}",
new { controller = "Gallery", action = "Index", id1 = new Int32Constraint(), id2 = new Int32Constraint() }
);
routes.MapRoute
(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
这是我的路线限制:
public class Int32Constraint : IRouteConstraint
{
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
if (values.ContainsKey(parameterName))
{
int intValue;
return int.TryParse(values[parameterName].ToString(), out intValue) && (intValue != int.MinValue) && (intValue != int.MaxValue);
}
return false;
}
}
/{domain.com}/PageSection/Edit/21
它在“TwoIntegers”路线处停止。很明显,没有传递第二个整数。
这是我的错误:
参数字典包含参数“id”的空条目 方法的不可空类型“System.Int32” 'System.Web.Mvc.ActionResult Edit(Int32)' 在 'SolutiaConsulting.Web.ContentManager.Controllers.PageSectionController'。 可选参数必须是引用类型、可空类型或 声明为可选参数。参数名称:参数
我做错了什么?我首先列出了更具体的路线。请帮忙。
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-routing