In my controller I have the following code:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(AdEntry adentry)
{
adentry.adDate = DateTime.Now;
adentry.adExpirationDate = DateTime.Now.AddDays(32);
adentry.adConfirmationID = rKeyGen(8);
if (ModelState.IsValid)
{
db.Items.Add(adentry);
db.SaveChanges();
TempData["Summary"] = adentry;
return RedirectToAction("Index");
}
return View(adentry);
}
In my Model I have this property:
[Required(ErrorMessage = "Confirmation Id is Required.")]
[StringLength(8, ErrorMessage = "{0} is too long.")]
public virtual String adConfirmationID { get; set; }
When I try to create a new Item ModelState.IsValid = false. The error I get is that Confiramtion Id is Required. I am setting the adConfirmationID = to a value right above the check. How can I get this check to pass?