Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Member
5 Points
49 Posts
Apr 03, 2012 08:43 AM|LINK
Hi There,
I'm trying to validate my model. The validation works once, the messages appear etc. When I try to submit the form again it does not validate.
What am I missing here?
Thanks in advance.
[HttpPost]
public ActionResult HandleFormSubmit([Bind(Prefix = "MyTestForm")] formModel model, FormCollection collection)
{
var value ="";
var value1 = "";
foreach (var key in Request.Form.AllKeys)
if (key.Equals("someModel.Name"))
if (Request.Form[key].Length <= 0)
ModelState.AddModelError(key, "Please provide a name");
}
if (key.Equals("someModel.Email"))
ModelState.AddModelError(key, "Please provide an email");
if (!ModelState.IsValid)
return CurrentUmbracoPage();
return RedirectToUmbracoPage(
new HiveId(
new Guid("71c84bd5d4014fd6b79fa01f00d09a65")));
mvc validation
bullrout@gma...
Member
5 Points
49 Posts
Model level validation only works once?
Apr 03, 2012 08:43 AM|LINK
Hi There,
I'm trying to validate my model. The validation works once, the messages appear etc. When I try to submit the form again it does not validate.
What am I missing here?
Thanks in advance.
[HttpPost]
public ActionResult HandleFormSubmit([Bind(Prefix = "MyTestForm")] formModel model, FormCollection collection)
{
var value ="";
var value1 = "";
foreach (var key in Request.Form.AllKeys)
{
if (key.Equals("someModel.Name"))
{
if (Request.Form[key].Length <= 0)
{
ModelState.AddModelError(key, "Please provide a name");
}
}
if (key.Equals("someModel.Email"))
{
if (Request.Form[key].Length <= 0)
{
ModelState.AddModelError(key, "Please provide an email");
}
}
}
if (!ModelState.IsValid)
{
return CurrentUmbracoPage();
}
return RedirectToUmbracoPage(
new HiveId(
new Guid("71c84bd5d4014fd6b79fa01f00d09a65")));
}
mvc validation