[英]ASP.NET Index method not being called after return view
So I'm pretty new to ASP.Net and I'm having some issues. 所以我对ASP.Net很新,我遇到了一些问题。 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): 我在LoginController中有这个代码(我知道这是不安全的):
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): 这是我正在调用的控制器/视图中的代码(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()? 我不应该通过返回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");
在
LoginController
使用RedirectToAction
而不是return View("~/Views/Home/index.cshtml");
: :
return RedirectToAction("Index", "Index");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.