Suppose i have a model with a validation
public class LoginModel
{
[Required(ErrorMessage="ID not entered")]
[StringLength(5,ErrorMessage = "Length should be 5")]
public string Id { get; set; }
}
In the view page i have a text box. When the validation fails. The controller returns to the view page with error message.
public ActionResult Login()
{
return View();
}
[HttpPost]
public ActionResult Login(LoginModel lg)
{
if(ModelState.IsValid)
{
return RedirectToAction("Index", "Home");
}
return View();
}
But the text box contains the previous values. How does it retains the value? And is there any way to avoid it?
Thanks