Regarding validation on multipe forms on single page
PROBLEM-1 My problem is there are 2 buttons Go and Resend.now when i
clicks on Resend button I have fired validation summary message which is
coming perfectly.but when I click on Go button previous validation message
is not getting cleared.How can i achieve this.
PROBLEM-2 Also one more thing i was facing earlier that I have Login and
Sign Up form on 1 page, now when i click on Signup button Validation
message was coming like "Please enter valid email".Along with that..red
color border was coming around textbox of Login Section.so how can i
Prevent such behaviour?
Note:-Below code is for Problem No-1
My Model is
public class loginmodel
{
[Required]
public string username { get; set; }
[Required]
public string password { get; set; }
}
My Controller is
[HttpGet]
public ActionResult Login1()
{
Mvc4KnockoutCRUD.Models.loginmodel obj = new Models.loginmodel();
return View(obj);
}
[HttpPost]
public ActionResult Login2()
{
ModelState.AddModelError("Error", "Shanti rakh ne chodu");
return View("Login1");
}
My View is :
@model Mvc4KnockoutCRUD.Models.loginmodel
@{
ViewBag.Title = "Login1";
}
<h2>Login1</h2>
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
@using (Html.BeginForm())
{
if (Request.Form.AllKeys.Contains("login-top"))
{
@Html.ValidationSummary()
}
@Html.TextBoxFor(m=>m.username)
@Html.TextBoxFor(m=>m.password)
@Html.Label("code", "Confirmation Code")
@Html.TextBox("code")
<input type="submit" name="login-top" value="Go" />
}
@using (Html.BeginForm("Login2", "Test2"))
{
if (Request.Form.AllKeys.Contains("login-main"))
{
@Html.ValidationSummary()
}
@Html.Label("email", "Email")
@Html.TextBox("email")
<input type="submit" name="login-main" value="Resend" />
}
No comments:
Post a Comment