【发布时间】:2011-09-11 22:18:43
【问题描述】:
好的,我的页面非常糟糕,我需要在这里得到很好的帮助。
我有一个登录页面,其中包含登录和注册部分视图。
RegisterView 有它自己的 ViewModel 类,这让我很头疼。
我使用“RenderAction”助手渲染注册部分视图。
最大的问题是验证。当我没有在注册字段中输入任何内容并单击提交时,注册部分视图不会在其父 LoginView 内更新,但只返回 RegisterView。换句话说,我的验证有效,但不是我希望它工作的地方。
LogOn.cshtml(这个包含注册部分视图)
<div id="regstrationForm">
@{Html.RenderAction("RegisterUser", "Account");}
</div>
注册(部分视图)
@using (@Ajax.BeginForm("RegisterUser", "Account", new AjaxOptions { UpdateTargetId = "reg" }))
{
<table id="reg">
...
<tr>
<td>
@Html.TextBoxFor(u => u.Username, new { @class = "registrationTextFields", placeholder = "Email" })
</td>
</tr>
<tr>
<td>
@Html.TextBoxFor(p => p.Password, new { @class = "registrationTextFields", placeholder = "Password" })
</td>
</tr>
<tr>
<td align="right">
<input class="signUpButton" type="submit" value="Sign up" />
</td>
</tr>
<tr>
<td>
@Html.ValidationMessage("myerrorsummary")
</td>
</tr>
</table>
这是用户点击注册按钮时的 HttpPost 控制器方法。
在这里,我尝试返回“PartialView()”并将我的输入字段变为红色 css 样式,但不显示这些字段下方的验证信息。
[HttpPost]
public ActionResult RegisterUser(RegisterViewModel logOnViewModel)
{
if (ModelState.IsValid)
{
MembershipCreateStatus result;
try
{
...
}
else
{
ModelState.AddModelError("myerrorsummary", "The input is not valid");
ViewBag.CountryList = countryRepository.GetAllCountries();
ViewBag.CityList = cityRepository.GetAllCitiesByCountryId(1);
return View(logOnViewModel);
}
}
【问题讨论】: