任何人都可以帮助我吗?我试图直接从另一个控制器的action方法调用 Home Controller 中的视图。我不想使用return redirectToAction()
方法,而是想直接调用HomeController
的视图。在HomeController
我有这个HttpGet方法:
public ActionResult SuperAdmin()
{
if (Session["User"] != null)
{
TempData["BindGrid"] = objDBContext.tbl_Student.Where(X => X.RegistrationConfirmed == false).ToList();
return View(); //Go to SuperAdmin View if condition is true
}
else
{
return View("Login", "Home"); //else redirect to Login view
}
}
现在控制器,我想从哪里调用HomeController SuperAdmin 查看
public ActionResult Search(string Search)
{
if (Session["User"] != null)
{
if (Search != string.Empty)
{
TempData["BindGrid"] = objDBContext.tbl_Student.Where(X => (X.UserName.StartsWith(Search) || Search == null) && (X.RegistrationConfirmed == false));
}
return View("SuperAdmin", "Home"); //If true, go to SuperAdmin view directly
}
else
{
return RedirectToAction("Login", "Home");
}
}
答案 0 :(得分:0)
您可以直接返回不同的视图,如:
return View("yourViewName", Model); //if it is in same controller and if you pass model then pass model in this way
如果您的视图位于不同的控制器中,那么
return View("FolderName/ViewName", Model ); // pass a view of a different controller with model. Just specify view name and it's folder name