所以我们在Login.cshtml中有这个表单
<form class="form-horizontal" action="LoginTest">
<div class="form-group">
<label for="inputEmail" class="col-sm-2 control-label">Gebruikersnaam</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="col-sm-2 control-label">Wachtwoord</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Registreer</button>
<button type="submit" class="btn btn-default">Annuleer</button>
</div>
</div>
</form>
我们有一个LoginController,下一个方法是LoginTest:
public ActionResult LoginTest(string inputEmail, string inputPassword)
{
Response.Write("<script>alert('" + inputEmail + "')</script>");
return null;
}
但是我们无法传递这些值。希望有人可以帮助我们!
答案 0 :(得分:0)
您需要通过名称标记传递这些值,而不是id标记,如下所示:
<form class="form-horizontal" action="LoginTest">
<div class="form-group">
<label for="inputEmail" class="col-sm-2 control-label">Gebruikersnaam</label>
<div class="col-sm-10">
<input type="text" name="inputEmail" class="form-control" id="inputEmail" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="col-sm-2 control-label">Wachtwoord</label>
<div class="col-sm-10">
<input type="password" name="inputPassword" class="form-control" id="inputPassword" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Registreer</button>
<button type="submit" class="btn btn-default">Annuleer</button>
</div>
</div>
</form>