entity framework - Solution for "Validation failed for one or more entities. See 'EntityValidationErrors' property for more details." -


i encountered error, did not provide detail root cause figured out problem is. wanted share others encounter might have success in solving problem.

i had following class:

    public class bankuser : identityuser, iuserprofile {     #region iuserprofile members     [display(name = "first name")]     public string firstname { get; set; }      [display(name = "last name")]     public string lastname { get; set; }      [required]     [display(name = "email address")]     [emailaddress(errormessage="invalid email address")]     public string email { get; set; }      [display(name = "time zone")]     public int timezone { get; set; }     public dictionary<string, string> timezoneoptions     {                 {             dictionary<string, string> d = new dictionary<string, string>();             d.add("(gmt -10:00) hawaii", "-10");             d.add("(gmt -9:00) alaska", "-9");             d.add("(gmt -8:00) pacific time", "-8");             d.add("(gmt -7:00) mountain time", "-7");             d.add("(gmt -6:00) central time", "-6");             d.add("(gmt -5:00) eastern time", "-5");             d.add("unknown", "0");             return d;         }     }      [display(name = "phone")]     [phone(errormessage = "invalid phone number.")]     [stringlength(10, minimumlength = 10, errormessage = "phone number must 10 characters long.")]     public string phone { get; set; }     #endregion } 

as can see, extended identityuser additional properties. view had username , password form fields when trying create new user usermanager.createasync(). when trying submit form username , password system try validate email passed since had required attribute.

        //     // post: /account/register     [httppost]     [allowanonymous]     [validateantiforgerytoken]     public async task<actionresult> register(registerviewmodel model)     {         if (modelstate.isvalid)         {             var user = new bankuser() { username = model.username };             var result = await usermanager.createasync(user, model.password);             if (result.succeeded)             {                 await signinasync(user, ispersistent: false);                 return redirecttoaction("index", "home");             }             else             {                 adderrors(result);             }         }          // if got far, failed, redisplay form         return view(model);     } 

solution must either add email field in form or remove required attribute. once did either of them code worked expected.

hope helps.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -