0
votes

I'm trying to get my JqGrid to update my database. I keep getting an Error: "Validation failed for one or more entities. See 'EntityValidationErrors' property for more details."

how do I find out what my actual error is or whats causing the error?

 // TODO:insert a new row to the grid logic here  
    [HttpPost]
    public string Create([Bind(Exclude = "Id")] AspNetUser obj)
    {
        //System.Diagnostics.Debug.WriteLine("Create");
        string msg;
        try
        {
            if (ModelState.IsValid)
            {
                db.AspNetUsers.Add(obj);
                //db.AspNetUsers.Add(new AspNetUser { UserName = obj.UserName, Email = obj.Email });
                db.SaveChanges();
                msg = "Saved Successfully";
            }
            else
            {
                msg = "Validation data not successfull";
            }
        }
        catch (Exception ex)
        {
            msg = "Error occured:" + ex.Message;
        }
        return msg;
    }
1
Its already telling you what to do - See 'EntityValidationErrors' property for more details."user3559349
Also if EntityValiationErrors is non in the exception ex, try looking for it within the inner exception.CodingYoshi
@stephenMuecke where do I find this property?Igorski88
@codingYoshi excuse my ignorance but how do I do that?Igorski88

1 Answers

0
votes

Usually this exception means the database is failing validation. This can occur if you have a set field in the database with a set character count and you are trying to save to that field a string which exceeds the database count.

Update your database string types with a 'varchar(max)' for example.

Hope this helps