c# - Data from AspNetUsers table error and "System.Collections.Generic.IEnumerable" error -


i want list userid , username columns aspnetusers table admin area's editprofile view.

my editprofile model is:

namespace adminpanelexercises1.areas.admin.models {    public class editprofilemodel    {       public int id { get; set; }       public string userid { get; set; }       public string username { get; set; }       public string useremail { get; set; }       public bool isadmin { get; set; }    } } 

my editprofile controller is:

private adminpanelexercises1.models.applicationuser db3 = new adminpanelexercises1.models.applicationuser();      // get: /admin/editprofile/     public actionresult index()     {          editprofilemodel epm = new editprofilemodel();         epm.userid = db3.id;         epm.username = db3.username;          return view(epm);     } 

my editprofile view is:

@model ienumerable<adminpanelexercises1.areas.admin.models.editprofilemodel>  @{    viewbag.title = "account management";    layout = "~/areas/admin/views/shared/_layout.cshtml";  }   <h2>index</h2>   <p> @html.actionlink("create new", "create") </p> <table class="table">     <tr>         <th>             @html.displaynamefor(model => model.userid)         </th>     <th>         @html.displaynamefor(model => model.username)     </th>      <th></th>     </tr>  @foreach (var item in model) { <tr>     <td>         @html.displayfor(modelitem => item.userid)     </td>     <td>         @html.displayfor(modelitem => item.username)     </td>      <td>         @html.actionlink("edit", "edit", new { id=item.id }) |         @html.actionlink("details", "details", new { id=item.id }) |         @html.actionlink("delete", "delete", new { id=item.id })     </td>    </tr>   }    </table> 

and i'm getting error like:

the model item passed dictionary of type 'adminpanelexercises1.areas.admin.models.editprofilemodel', dictionary requires model item of type 'system.collections.generic.ienumerable`1[adminpanelexercises1.areas.admin.models.editprofilemodel]'.

how can fix problem? writting wrong code getting data aspnetusers table?

your view expecting model of ienumerable (ienumerable<adminpanelexercises1.areas.admin.models.editprofilemodel>) , returning single item controller.

your view should have model like:

@model adminpanelexercises1.areas.admin.models.editprofilemodel 

if going show multiple records in view controller should return multiple items (not single item, current code)


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -