I am new to MVC and I m building a website using ASP.Net MVC5.I m a little confused with the routing concept. The following is my route.config file that I have. so Whenever I go to my home page or login page and enter my credentials and click the submit button, I do see that the page allows me to go to the next page where I can find my info but the URI changes to the name of the post action that the submit button triggered. for instance if my home login page URI is this
when clicked on submit the url becomes
http://localhost/home/submit but the view that I load is called AccountInfo not sure how this works.
Also I m storing the user information in a session and there is a logoff button so when I click the button I m setting the session to null and redirecting to the login action, but then my url changes to something like this, though I dont have any url which has a parameter as part of the url in my route.config.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Test",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "TESTVIEW", id =
UrlParameter.Optional }
);
routes.MapRoute(
name: "Invoice",
url: "{Home}/{Invoice}/{q}",
defaults: new { controller = "Home", action = "GetInvoice", q =
UrlParameter.Optional }
);
routes.MapRoute(
name: "Error",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Error", id =
UrlParameter.Optional }
);
routes.MapRoute(
name: "ResetPassword",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "ResetPassword", id
= UrlParameter.Optional }
);
routes.MapRoute(
name: "Accounts",
url: "{controller}/{action}",
defaults: new { controller = "Home", action = "AccountStatus" }
);
routes.MapRoute(
name: "Register",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Register", id =
UrlParameter.Optional }
);
routes.MapRoute(
name: "Home",
url: "Home",
defaults: new { controller = "Home", action = "Login"}
);
routes.MapRoute(
name: "Home1",
url: "",
defaults: new { controller = "Home", action = "Login" }
);
}
Action method
/// <summary>
/// Logoffs this instance.
/// </summary>
/// <returns></returns>
public ActionResult Logoff()
{
Session["AccountInfo"] = null;
//return View("Login");
return RedirectToAction("Login", new CustomerModel()); //
View("Login", new CustomerModel());
}
My Submit action is below
[ValidateAntiForgeryToken]
public ActionResult Submit(CustomerModel customerModel)
{
homeAccountViewModel = new HomeAccountStatusViewModel ();
homeAccountViewModel.Customer = customerModel;
if (ModelState.IsValidField("Username") &&
(ModelState.IsValidField("Password")))
{
logic here....
return View("AccountStatus", homeAccountViewModel);
}
else
{
return View("Login", customerModel);
}
}
Any help will be a great favour. Thanks