c# - "The UserId field is required" - entity validation error -


i'm using asp.net identity base on entity framework mvc(5) app.

problem :

when want register new user , entity validation error. looked @ validation error property , 2 error(both same actually) on line :

         var result = await usermanager.createasync(user, model.password); 

errors :

http://i62.tinypic.com/11acy0y.png

now.....i have no idea 'userid' field coming from. looked @ identityuser base classes , not belong either , there "id" field works properly.

if more info needed mention in comment plz.

so have idea....what field ? , how solve this?

edit : forgot mention create base user in seed method of dbinitializer....that works fine. in controller error.

controller & related action :

    //     //post : /account/register     [httppost]     [allowanonymous]     [validateantiforgerytoken]     public async task<actionresult> register(register_viewmodel model)     {         usermanager.uservalidator = new myuservalidation();          //complete user object if model valid         if (modelstate.isvalid)         var user = new employee         {          .......         }          //store claims             ........                   // error                 var result = await usermanager.createasync(user, model.password);                  if (result.succeeded)                 {                     await signinasync(user, ispersistent: false);                     return redirecttoaction("index", "home");                 }                 else                 {                     adderrors(result);                 }                                      }         return view(model);     } 

view :

     @model univercity_project.models.viewmodels.register_viewmodel       @{      viewbag.title = "register_tab";      layout = "~/views/shared/layout.cshtml";      }       <h2>register_tab</h2>        @using (html.beginform("register","account",formmethod.post))       {      @html.antiforgerytoken()       <div class="form-horizontal">     <h4>employee</h4>     <hr />         <!-- nav tabs -->         <ul class="nav nav-tabs" role="tablist">           <!-- nav tabs here! -->         </ul>          <!-- tab panes -->         <div class="tab-content">         <!-- nav-tabs content  here! -->            <div class="form-group">                     <div class="col-md-offset-2 col-md-10">                         <input type="submit" value="submit" class="btn btn-     default" />                     </div>                 </div>             </div> 

employee(or 'applicationuser' ) model :

  public class employee : identityuser {      public string employment_number { get; set; }      public string gender { get; set; }      public int national_id { get; set; }      public string first_name { get; set; }      public string last_name { get; set; }      public string father_name { get; set; }      public string birth_place { get; set; }      public datetime birth_date { get; set; }      public string serial_alphabetic { get; set; }      public int serial_numeric { get; set; }      public int number_of_people_under_support { get; set; }        //<----------------------------------------------------------------------------------------------------------->      public virtual employment_status employment_status { get; set; }     public int employment_info_id { get; set; }      public virtual marriage_status marriage_status { get; set; }     public int marriage_info_id { get; set; }      public virtual job_status job_status { get; set; }      public virtual academic_status academic_status { get; set; }      public virtual phone_number phone_number { get; set; }      public virtual war_record war_record_info { get; set; }      public virtual address address { get; set; }      public virtual insuarance insuarance_info { get; set; }   } 

thank u in advance.

ok here solution :

in part adding claims didnt know should assign value userid property here doing :

                    user.claims.add(new identityuserclaim() { claimtype = claimtypes.gender, claimvalue = user.gender}); 

and here should have done :

                    user.claims.add(new identityuserclaim() { claimtype = claimtypes.gender, claimvalue = user.gender, userid = user.id }); 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -