I have a small application where i an creating a customer
[Authorize]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CreateCustomer(GWCustomer customer)
{
if (string.IsNullOrEmpty(customer.CustomerName))
{
ModelState.AddModelError("CustomerName", "The name cannot be empty");
}
....
if (ModelState.IsValid)
{
//insert in db
}
}
My problem is that the GWCustomer object has an Id, which is primary key and cannot be null. This makes the validation framework flag it as an error. But its not an error, i havent created the customer yet - and for now is should be null until it gets saved. How do I bypass this? or fix it?
I never get to insert it in the DB becuase the ModelState is never valid.
Edit I am using Linq to SQL, and a repository pattern