c# - Asp set role ModelState.IsValid is false -


hi there) i'm newbie in asp , i'm realizing role based security in project, using applicationusers class. created page, admin can set roles users, can't set role user, because in edit post method modelstate.isvalid value false, because can't convert string id value role. tried set value modelstate, can't because hasn't setter. help, please, how can fix way? code below...

    public actionresult edit(string id)     {         if (id == null)         {             return new httpstatuscoderesult(httpstatuscode.badrequest);         }         applicationuser applicationuser = db.users.find(id);         if (applicationuser == null)         {             return httpnotfound();         }         var roles = db.roles.select(x => new selectlistitem { text = x.name, value = x.id }).toarray();         viewbag.roles = roles;         return view(applicationuser);     }      // post: applicationusers/edit/5     // Чтобы защититься от атак чрезмерной передачи данных, включите определенные свойства, для которых следует установить привязку. Дополнительные      // сведения см. в статье http://go.microsoft.com/fwlink/?linkid=317598.     [httppost]     [validateantiforgerytoken]     public actionresult edit([bind(include = "id,email,emailconfirmed,passwordhash,securitystamp,phonenumber,phonenumberconfirmed,twofactorenabled,lockoutenddateutc,lockoutenabled,accessfailedcount,username,roles")] applicationuser applicationuser)     {         if (modelstate.isvalid)         {             db.entry(applicationuser).state = entitystate.modified;             db.savechanges();             return redirecttoaction("index");         }         return view(applicationuser);     } 

and view:

    <div class="form-group">         @html.labelfor(model => model.roles, htmlattributes: new { @class = "control-label col-md-2" })         <div class="col-md-10">             @html.dropdownlistfor(x => x.roles, (ienumerable<selectlistitem>)viewbag.roles, new { htmlattributes = new { @class = "form-control" } })             @html.validationmessagefor(model => model.roles, "", new { @class = "text-danger" })         </div>     </div> 

try set breaking point after if (modelstate.isvalid) in opening { see missing problem propriety haven't set? may there 1 required propriety in applicationuser object not set or datatype not correct.


Comments

Popular posts from this blog

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

wordpress - (T_ENDFOREACH) php error -

Using django-mptt to get only the categories that have items -