我是 MVC 框架的新手;我正在尝试学习。
我正在尝试从登录重定向到主页
[HttpPost]
public ActionResult Login(Register model)
{
StudentDBHandle db = new StudentDBHandle();
DataTable dst = db.Login(model);
if (dst.Rows.Count==1)
return RedirectToAction("Index","Student");
else
{
ViewBag.Message = "Login Failed";
return View();
}
}
它说“路由表中没有路由与提供的值匹配。”
所以我在 routeconfig 文件中添加了路由
public static void RegisterRoutes(RouteCollection routes
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Login",
url: "{controller}",
defaults: new { controller = "Register", action = "Login", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "HomePage",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Student", action = "Index", id = UrlParameter.Optional }
);
}
当登录成功时,它会重定向到相同的登录页面
我已经更改了顺序,但它不起作用。