我在索引视图上使用 LogOn 部分视图并使用 MVC3 的默认 LogOnModel。但是,没有足够的地方在视图中显示验证消息。如何使用 javascript 警报窗口显示验证消息?
[HttpPost]
public ActionResult LogOn( LogOnModel model, string returnUrl )
{
if ( ModelState.IsValid )
{
if ( ( model.UserName != null ) && ( model.Password != null ) )
{
if ( Membership.ValidateUser( model.UserName, model.Password ) )
{
FormsAuthentication.SetAuthCookie( model.UserName, true );
if ( Url.IsLocalUrl( returnUrl ) && returnUrl.Length > 1 && returnUrl.StartsWith( "/" )
&& !returnUrl.StartsWith( "//" ) && !returnUrl.StartsWith( "/\\" ) )
{
return Redirect( returnUrl );
}
else
{
return RedirectToAction( "Index", "Home", model );
}
}
else
{
return RedirectToAction( "Index", "Home" );
}
}
else return RedirectToAction( "Index", "Home" );
}
return RedirectToAction( "Index", "Home" );
}
在索引视图中:
@Html.Partial( "LogOn" )
和登录视图:
@model OnlineMarket.Models.LogOnModel
@using ( Html.BeginForm( "LogOn", "Home", FormMethod.Post ) )
{
@Html.ValidationSummary( true )
@Html.Hidden( "RememberMe", "true" )
<ul class="forms">
<li class="txt">Username</li>
<li class="inputfield">
@Html.TextBoxFor( m => m.UserName, new { @class = "logininputs" } )
</li>
</ul>
<ul class="forms">
<li class="txt" style="width: 26px;">Password</li>
<li class="inputfield">
@Html.TextBoxFor( m => m.Password, new { @class = "logininputs" } )
</li>
</ul>
<ul class="forms">
<li class="txt" style="width: 50px; margin-top: -5px; margin-left: 4px;">
<input type="submit" value="Enter" class="buttonforinput" style="height: 23px;" />
</li>
</ul>
}