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
是一個字符串,請幫我解決這個錯誤。