0
我有一个具有以下作用的控制器的类型:必须有一个字符串值,或者是它实现IRouteConstraint
public ActionResult Post(int pId)
{
urlPostTitle = "Hello";
pId=23;
return RedirectPermanent(Url.Action("PostRedirect", new { pId = pId, postTitle = urlPostTitle }));
}
我的路线为:
routes.MapRoute("GetPostRedirect", "{pId}/{postTitle}", new { controller = "Blog", action = "PostRedirect", }, new { pId = @"^\d{1,3}$", postTitle = UrlParameter.Optional });
但我得到这个错误在return RedirectPermanent
行:
The constraint entry 'postTitle' on the route with URL '{pId}/{postTitle}' must have a string value or be of a type which implements IRouteConstraint.
我无法理解的原因错误为urlPostTitle
是一个字符串,请帮我解决这个错误。