這個問題已被問了很多次,但我不認爲我需要它的方式。局部視圖登錄主頁
我試圖在主頁上實現登錄表單,但此表單位於彈出式部分,就像您在此網站上所示:http://myanimelist.net。
我創建了一個局部視圖我的登錄表單:
@model ArtWebShop.Models.customers
@section Validation {
@Scripts.Render("~/bundles/jqueryval")
}
<section id="login">
@using (Html.BeginForm("LoginValidate", "Login", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.ValidationSummary(true)
@Html.ValidationSummary()
<fieldset>
<legend>Login</legend>
@Html.LabelFor(model => model.email)
@Html.TextBoxFor(m => m.email)
@Html.LabelFor(m => m.password)
@Html.PasswordFor(m => m.password)
<input type="submit" value="Login" class="button" />
</fieldset>
}
</section>
這是在主頁(index.cshtml)所示:
<section class="shown">
@Html.Partial("_LoginPartial")
@Html.ValidationSummary(true)
@Html.ValidationSummary()
</section>
局部視圖顯示正確。 但現在來了不起作用的部分。
當你按登錄,如果你沒有填寫字段,驗證是在我的LoginController中完成,因爲它應該但我似乎無法將錯誤發送到我的主頁視圖時,我重定向。
[HttpPost]
public ActionResult LoginValidate(string redirect)
{
if (_unitOfWork.CustomersRepository.CostumerIsValid(Request.Form["email"], Request.Form["password"]))
{
if (!String.IsNullOrEmpty(redirect) || String.Compare(redirect, "none", StringComparison.OrdinalIgnoreCase) == 0)
{
if (redirect != null) Response.Redirect(redirect, true);
}
else
{
return RedirectToAction("index", "Home");
}
}
ModelState.AddModelError("email", "You entered an incorrect email address");
ModelState.AddModelError("password", "You entered an invalid password");
return RedirectToAction("index", "Home");
}
這是我的loginValidation。由於沒有填充任何錯誤,所以將錯誤添加到ModelState中,然後重定向到主頁。但是,這並沒有顯示我的錯誤。我猜測這完全是因爲我重定向,但我該如何解決這個問題?
如何打開登錄彈出窗口?你想和你提供的鏈接有相同的行爲嗎?爲什麼在出現錯誤時關閉彈出窗口?是不是更好的行爲像這裏:http://www.minidevils.de/minibreakdown/# –
這確實是一個更好的例子。我使用我在OP中提供的鏈接來顯示我的意思是登錄彈出窗口,以防它不清楚。 –