I am working on a login page.
However, I am facing issue with the validation. Is there a way to disable the forget user validation or the user and password validation based on the option they chose?
VIEW.cshtml
<div id="login-content">
<div class="vertical-tab">
@* LOGIN *@
<div id="section1" class="section-w3ls">
<input type="radio" name="sections" id="option1" checked>
<label for="option1" class="icon-left-w3pvt">
<span class="fa fa-user-circle" aria-hidden="true"></span>Login
</label>
<article>
@using (Html.BeginForm("DoLogin", "Subscriber", new { ReturnUrl = Request["ReturnURL"] },
FormMethod.Post, new { @style = "background-color : #fff; padding : 2em" }))
{
@Html.AntiForgeryToken()
<h3 class="legend">Log In</h3>
<div class="input">
@* Username *@
<span class="fa-solid fa-user" aria-hidden="true"></span>
@Html.TextBoxFor(model => model.UserName, new { placeholder = "Username" })
</div> @Html.ValidationMessageFor(model => model.UserName, "", new { @class = "text-danger" })
<div class="input">
@* Password *@
<span class="fa fa-key" aria-hidden="true"></span>
@Html.PasswordFor(model => model.Password, new { placeholder = "Password", @Autocomplete = "off" })
</div> @Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })
<input type="submit" class="btn-login" value="Log In">
}
</article>
</div>
@* FORGET PASSWORD *@
<div id="section2" class="section-w3ls">
<input type="radio" name="sections" id="option3">
<label for="option3" class="icon-left-w3pvt">
<span class="fa fa-lock" aria-hidden="true"></span>Forgot Password?
</label>
<article>
@using (Html.BeginForm("DoLogin", "Subscriber",
FormMethod.Post, new { @style = "background-color : #fff; padding : 2em" }))
{
@Html.AntiForgeryToken()
<h3 class="legend last">Reset Password</h3>
<p class="para-style">
Fill in your username and we will send the password to your registered email.
</p>
<div class="input">
@* Username **@
<span class="fa-solid fa-user" aria-hidden="true"></span>
@Html.TextBoxFor(m => m.forgetusername, new { @class = "form-control" })
</div>
@Html.ValidationMessageFor(model => model.forgetusername, "", new { @class = "text-danger" })
@Html.ValidationMessage("ForgotPasswordErr", new { @class = "text-danger" })
<input type="submit" class="btn submit" value="Submit">
}
</article>
</div>
</div>
<div class="clear"></div>
</div>
Controller ( have not completed the code )
public ActionResult DoLogin(LoginViewModel loginVM, string returnURL)
{
if (ModelState.IsValid)
{
string ErrMsg = "";
if (Validate(loginVM, out ErrMsg))
{
Session["LoginViewModel"] = loginVM;
Session["Allowpasswordchange"] = loginVM.Account.allowchangepassword;
Session["ReturnURL"] = returnURL;
return RedirectToAction("TermsAndConditions");
}
else
{
ModelState.AddModelError("CredentialError", ErrMsg);
if (returnURL != null)
{
ViewBag.ReturnUrl = returnURL;
}
return View("Login");
}
}
if (returnURL != null)
ViewBag.ReturnUrl = returnURL;
return View("Login", loginVM);
}