大家好,我想问一下如何将数据从视图发送到控制器?我想用我的控制器和视图描述我的问题,如下所示
这是登录动作控制器
[HttpPost]
public ActionResult Login(Panel model, string Username, string Password, string CaptchaValue, string InvisibleCaptchaValue)
{
bool cv = CaptchaController.IsValidCaptchaValue(CaptchaValue.ToUpper());
bool icv = InvisibleCaptchaValue == "";
if (!cv || !icv)
{
ModelState.AddModelError(string.Empty, "The Captcha Code you entered is invalid.");
}
if (ModelState.IsValid)
{
if (model.Username == Username && model.Password == Password)
{
FormsAuthentication.SetAuthCookie(model.Username, false);
return RedirectToAction("index", "Home");
}
else
{
ModelState.AddModelError("", "Check your name or password");
}
}
return View();
}
因此,当用户登录时,重定向到主页/索引视图。此时一切正常。
这是我的索引视图:
[Authorize]
public ActionResult index()
{
return View();
}
我的问题是如何保存用户的密码参数并从索引视图发送到不同的控制器以在控制器方法中使用此参数但是如何?例如,我想在 where 子句中的 index_test 控制器方法中使用密码参数,但首先我需要从 index.html 发送这些数据。
public ActionResult index_test()
{
return View(db.contents.Where(x => x.test_parameter== password).ToList());
}