在我的两个部分观点中,我面临验证问题
_partialA.cshtml
@model demo3.Models.ModelA
@using (Html.BeginForm("TEST", "Home")) {
<h2>_partialA</h2>
<div>
@Html.EditorFor(m => m.EmployeeId)
@Html.ValidationMessageFor(m => m.EmployeeId)
</div>
<div>
@Html.EditorFor(m => m.EmployeeName)
@Html.ValidationMessageFor(m => m.EmployeeName)
</div>
<input class="mainbutton" type="submit" value="TEST"/><br />
}
另一个部分观点是
_partialB.cs.html
@model demo3.Models.ModelB
@using (Html.BeginForm("CreateAgreement", "Home"))
{
<h2>_partialB</h2>
<div>
@Html.EditorFor(m => m.Comapny)
@Html.ValidationMessageFor(m => m.Comapny)
</div>
<div>
@Html.EditorFor(m => m.FisacalYear)
@Html.ValidationMessageFor(m => m.FisacalYear) </div>
<input class="mainbutton" type="submit" value="CreateAgreement"/><br />
}
这是我的控制器代码
[HttpPost]
public ActionResult CreateAgreement(ModelB modelb)
{
if (ModelState.IsValid)
{
return View("Start", modelb);
}
return View("Start", modelb);
}
[HttpPost]
public ActionResult TEST(ModelA modela)
{
if (ModelState.IsValid)
{
return View("Start", modela);
}
return View("Start", modela);
}
public ActionResult Start()
{
return View();
}
public ActionResult FirstView()
{
ModelA objA = new ModelA();
return PartialView("_partialA", objA);
}
public ActionResult SecondView()
{
ModelB objB = new ModelB();
return PartialView("_partialB", objB);
}
现在我在点击按钮时没有收到任何错误消息..还有另一件事..我的两个视图都被打开了..点击按钮..如何防止这种情况发生?