我中都有登錄局部視圖中的AccountController:MVC3部分視圖回發不工作?
public ActionResult LogOn()
{
return PartialView();
}
//
// POST: /Account/LogOn
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (ModelState.IsValid)
{
if (MembershipService.ValidateUser(model.UserName, model.Password))
{
FormsService.SignIn(model.UserName, model.RememberMe);
}
else
{
ModelState.AddModelError("", Resources.Account.Account.LoginFailureText);
}
}
}
return PartialView(model);
}
,我使這個部分我_Layout.cshtml有:
@{Html.RenderAction("LogOn", "Account");}
和LogOn.cshtml的看法是:
@model Kalimat.Web.Models.LogOnModel
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<div class="leftbanner login">
<div class="bookicon">
<img src="@Url.Content(@Kalimat.Web.Resources.Common.bookiconImgSrc)" alt="@Kalimat.Web.Resources.Common.bookiconImgAlt" />
</div>
<div class="strip">
@MvcHtmlString.Create(Kalimat.Web.Resources.Account.Account.LoginTitle)
</div>
<div class="shade_2">
<img src="@Url.Content(@Kalimat.Web.Resources.Common.shade_2ImgSrc)" alt="@Kalimat.Web.Resources.Common.shade_2ImgAlt" />
</div>
<div class="insidetext">
@{
//Logined user view
if (Request.IsAuthenticated)
{
<div id="LoginView1">
@{<text>@Kalimat.Web.Resources.Account.Account.WelcomeText <strong>@Model.UserName</strong>!</text>}
<br />
<a id="LoginStatus1" href="">@Kalimat.Web.Resources.Account.Account.LoginStatusText</a>
<a id="ChangePassLinkButton" href="">@Kalimat.Web.Resources.Account.Account.ChangePswText</a>
</div>
}
else
{
@Html.LabelFor(m => m.UserName)
@Html.TextBoxFor(m => m.UserName, new { @class = "inputfield" })
@Html.ValidationMessageFor(m => m.UserName, "*")
<br />
@Html.LabelFor(m => m.Password)
@Html.PasswordFor(m => m.Password, new { @class = "inputfield" })
@Html.ValidationMessageFor(m => m.Password, "*")
<br />
<span class="remove_shop">
@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)
</span>
<p>
***<input type="submit" class="submit_Cart" value="@Kalimat.Web.Resources.Account.Account.LoginButtonText" />***
</p>
@Html.ValidationSummary(false, Kalimat.Web.Resources.Account.Account.LoginFailureText)
<a class="submit_Cart" href="">@Kalimat.Web.Resources.Account.Account.NewAccountText</a>
<br />
<a class="submit_Cart" href="">@Kalimat.Web.Resources.Account.Account.RecoverPswText</a>
}
}
</div>
</div>
當我運行應用程序LogOn視圖渲染正確,但當點擊提交按鈕時什麼也沒有發生。爲什麼?
感謝您的回答,但是在使用此解決方案時,首次查看與驗證錯誤一起顯示,並提交視圖時,它不呈現以反映用戶登錄,直到刷新頁面 –
您使用的是 Html.EnableClientValidation();在ajax.beginform()之前的 ?並在你的行動,當你履行所有的檢查,如用戶驗證,那麼你不必呈現相同的HTML ...因爲您已經使用過表單,因此在控件上創建另一個使用相同模型的div,但表示用戶已登錄或在此處添加UpdateTargetId屬性: 新的AjaxOptions {UpdateTargetId = [divid],OnBegin = [someFunction],OnFailure = [failureFunction]} 所以當行動是成功的,它會顯示這個div而不是那個......但它完全取決於你如何管理你所呈現的html ... –
chk this out http://stackoverflow.com/questions/5733541/rendering-view-in-asp-net-mvc –