, , (!) . javascript POST , , .
, ASP.NET MVC . :
public ActionResult SaveSomething(Something thing)
{
if(!ModelState.IsValid)
{
return View("EditSomething", thing);
}
}
... , , , , , [Required] [StringLength(x)]. . [Remote] .
[Remote], :
public ActionResult CheckThingCodeValidity(string code)
{
return Json(_thingCodeChecker.ThingCodeWorks(code), JsonRequestBehavior.AllowGet);
}
... - :
public ActionResult SaveSomething(Something thing)
{
if(!_thingCodeChecker.ThingCodeWorks(thing.Code))
{
ModelState.AddModelError("Code", "This code is not valid.");
}
if(!ModelState.IsValid)
{
return View("EditSomething", thing);
}
}
, , , , , .
, , , . , , , , . - - , , , .