我有一个视图,其中有3个输入TextBox和2个输入提交按钮:我将通过他的帐号或他的RIB号搜索客户帐户。当我为提交实现控制器方法操作时按钮我只检索帐户attributs的实验室。任何帮助PLZ !!
观点:
@using (Html.BeginForm("SearchCompte", "Compte", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.Label("NumCompte", new { @class = "col-md-2 control-label" })
<div class="col-md-3">
@Html.TextBox("NumCompte","", new { @class = "form-control", @placeholder = "N° Compte"})
@Html.ValidationMessage("NumCompte", "", new { @class = "text-danger" })
</div>
@Html.Label("CléRIB", new { @class = "col-md-1 control-label" })
<div class="col-md-2">
@Html.TextBox("CléRIB", "",new { @class = "form-control", @placeholder = "Clé" })
@Html.ValidationMessage("CléRIB", "", new { @class = "text-danger" })
</div>
<div class=" col-md-2">
<input type="submit" name="Search1" value="Search" class="btn btn-primary" />
</div>
</div>
<div class="form-group">
@Html.Label("RIB", new { @class = "col-md-2 control-label" })
<div class="col-md-3">
@Html.TextBox("RIB","", new { @class = "form-control", @placeholder = "RIB Compte" })
@Html.ValidationMessage("RIB", "", new { @class = "text-danger" })
</div>
<div class=" col-md-2">
<input type="submit" name="Search2" value="Search" class="btn btn-primary" />
</div>
</div><br /><br />
<aside>
<img src="~/Content/Img/Capturerib.PNG" class="img-responsive col-md-push-7 col-md-4" alt="Responsive image" width="400" height="500">
</aside>
@ViewBag.Message
}
</section>
</div>
控制器:
[HttpGet]
public ActionResult SearchCompte()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult SearchCompte(string RIB)
{
Compte cp = service.GetCompteByRIB(RIB);
if (cp != null)
{ return RedirectToAction("DetailsCompte", "Compte",new {RIB }); }
//return View(cp);
else
{ return Content("Le compte recherché n'existe pas!!!! "); }
}
public ActionResult DetailsCompte(string s)
{
Compte cp = service.GetCompte(s);
return View(cp);
}
结果: