在我的控制器中
[HttpPost]
public ActionResult Login(string email, string password)
{
var isValid = db.Users.FirstOrDefault(m => m.Email == email && m.Password == password);
if(isValid == null)
{
ViewBag.Error = 1;
}
else
{
}
return View();
}
并查看
</div>
<div class="form-group has-feedback">
<input name="password" type="password" class="form-control" placeholder="Password" required>
</div>
<div class="form-group has-feedback">
<button type="submit" class="btn btn-primary btn-block btn-flat">Sign In</button>
</div>
</form>
我想在提交给控制器之后检索表单值我没有使用任何模型而我想要没有模型怎么能这样做????
答案 0 :(得分:0)
是的,您可以将属性name
指定为parameter name
,这样您的观点就像
@using (Html.BeginForm("Login", "controllername", FormMethod.Post))
{
<div class="form-group has-feedback">
<input name="email" type="email" class="form-control" placeholder="email" required>
</div>
<div class="form-group has-feedback">
<input name="password" type="password" class="form-control" placeholder="Password" required>
</div>
<div class="form-group has-feedback">
<button type="submit" class="btn btn-primary btn-block btn-flat">Sign In</button>
</div>
}
你的行动就像
[HttpPost]
public ActionResult Login (string password,string email)
{
var isValid = db.Users.Any(m => m.Email == email && m.Password == password);
if(isValid)
{
ViewBag.Error = 1;
}
else
{
}
return View();
}
我用Any
代替FirstOrDefault
因为它会返回bool
值意味着如果发现它将返回true
其他false