1

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.

1 Answer 1

3

Use RedirectToAction in your LoginController instead of return View("~/Views/Home/index.cshtml");:

return RedirectToAction("Index", "Index");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.