我收到此错误“在路径集合中找不到名为’MemberRoute’的路径.参数名称:名称”.这是我的Global.asax,
public class MvcApplication : System.Web.HttpApplication { public static void RegisterRoutes(RouteCollection routes) { routes.MapRoute( "MemberRoute",// routeName "member/{userId}/{pseudoName}",// url new { // url defaults controller = "Member",action = "Index",userId = 0,pseudoName = UrlParameter.Optional },new { // url constraints userId = @"\d+" // must match url {userId} } ); } protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); } }
MemberController,
public ActionResult Index(int userId,string pseudoName) { User user; var unitOfWork = new UnitOfWork(); user = unitOfWork.UserRepository.GetById(userId); var expectedName = user.PseudoName.ToSEOUrl(); var actualName = (pseudoName ?? "").ToLower(); // permanently redirect to the correct URL if (expectedName != actualName) return RedirectToActionPermanent("Index","Member",new { id = user.UserId,pseudoName = expectedName }); return View(user); }
呼叫者,
return RedirectToRoute("MemberRoute",new { userId = user.UserId,pseudoName = user.PseudoName });
为什么找不到路线名称?