Reputation: 647
RedirectToAction method doesn't work, can't solve it for the past 4 hours. Here is the code from the User controler:
[HttpPost, ValidateAntiForgeryToken]
public ActionResult Register(UsersNew form)
{
var user= new User();
UserDB db = new UserDB();
db.addUser(form.Username, form.Password, form.SchoolName, form.Country, form.City);
return RedirectToAction("Home");
}
It says that there is no route registered like that, although it adds users to the database, so only redirect does not work. This is my routeConfig file:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("Home", "", new { controller = "First", action = "FirstView" });
routes.MapRoute("Register", "register", new { Controller = "Users", action = "Register" });
routes.MapRoute("About", "about", new { Controller = "About", action = "About" });
}
Upvotes: 1
Views: 295
Reputation: 4382
Because Home
is not an action, it's route. You should use RedirectToRoute.
return RedirectToRoute("Home");
Upvotes: 2