你好另一个控制器项目中,我与用户名通过一条欢迎信息索引页 它是一个MVC3 ASP.Net剃刀项目如何从一个控制器值传递给在ASP.Net MVC3
有两个控制器在那里;一个是登录控制器,另一个是主控制器。从登录控制器,我必须将登录人的用户名传递到视图页面。
登录控制器重定向到另一个名为Home Controller的控制器。从那里我必须将该值传递给视图页面。这是我的问题。我已经尝试用单个控制器来查看它的工作情况。
我无法使用单个控制器,因为登录控制器使用登录页面和主页控制器使用主页。两者都是分开的看法。
我试过像这样,但它不工作。你能提出一个好的方法来遵循?
登录控制器
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(LoginModel model)
{
if (ModelState.IsValid)
{
if (DataAccess.DAL.UserIsValid(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, false);
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", "Invalid Username or Password");
}
}
return View();
}
家庭控制器
public ActionResult Index()
{
return View();
}
将数据作为参数传递给RedirecttoAction不起作用。原因已在这个答案中解释 - https://stackoverflow.com/a/32174158/5333178 –
根据MSDN和我做了什么工作https://msdn.microsoft.com/it-it/library /system.web.mvc.controller.redirecttoaction(v=vs.118).aspx – theLaw