i have a question about modelstate in asp.net mvc3 that , i have a contoller suppose Home and a action in it submitform . now first time i submit my form to this action and user entered someting wrong i returened error using modelstate
ModelState.AddModelError("", "Your entered date is wrong .");
Now when user submit form again this time suppose date is correct but he entered wrong name this time , now when i return error at this step
ModelState.AddModelError("", "name should be at least 4 character long .");
but now when i return this i see name should be at least 4 character long . and also see Your entered date is wrong. , what the problem ?
following is my full code
[Authorize]
[System.Web.Mvc.OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
public class HomeController : Controller
{
public ActionResult Formsubmit(mymodel RModel)
{
if(RModel.date != "2/2/2012")
{
ModelState.AddModelError("", "Your entered date is wrong .");
}
if(RModel.name.cout() < 4)
{
ModelState.AddModelError("", "name should be at least 4 character long .");
}
return View(RModel);
}
}
1 Answer