So I'm pretty new to ASP.Net and I'm having some issues. The problem is when I want to call upon a new controller and show the corresponding view, the index method in that controller does not get activated.
I have this code in my LoginController (I know this is insecure):
public ActionResult LoginTest(string inputEmail, string inputPassword, string submit)
{
if(submit != null)
{
Session["email"] = inputEmail;
return View("~/Views/Home/index.cshtml");
}
return null;
}
And this is the code in the controller/view I'm calling (HomeController):
public ActionResult Index()
{
if(Session["email"] != null)
{
ViewBag.HelloWorld = Session["email"].ToString();
} else
{
ViewBag.HelloWorld = "Does not work.";
}
return View();
}
Am I not supposed to do this through return View()? Is there a method that calls the controller which calls the corresponding view?
Any help is appreciated.
Use RedirectToAction
in your LoginController
instead of return View("~/Views/Home/index.cshtml");
:
return RedirectToAction("Index", "Index");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.