c# - The model item passed into the dictionary is of type 'System.Data.Entity.DynamicProxies.Survey_D8 -


i have error. is

the model item passed dictionary of type 'system.data.entity.dynamicproxies.survey_d8226c5f5e348399740ede08fdf0a956bdad893915272c075af983b0c50da25e', dictionary requires model item of type 'surveyspaceproject.models.user'.

i taking survey database need user. tried solutions stackoverflow there no way. can me please? not homework. project , started asp.net 1 week ago.

my view         public actionresult fillsurvey(int id)         {             var s = sspentity.getdb().surveys.firstordefault(x => x.id == id);             return view(s);         } 

my fillsurvey page :

       @model surveyspaceproject.models.survey       @{     viewbag.title = "fillsurvey";     }      <h2>fillsurvey</h2>      <div>     <h4>survey</h4>     <hr />     <dl class="dl-horizontal">         <dt>             @html.displaynamefor(model => model.user.username)         </dt>          <dd>             @html.displayfor(model => model.user.username)         </dd>          <dt>             @html.displaynamefor(model => model.title)         </dt>          <dd>             @html.displayfor(model => model.title)         </dd>          <dt>             @html.displaynamefor(model => model.createddate)         </dt>          <dd>             @html.displayfor(model => model.createddate)         </dd>          <dt>             @html.displaynamefor(model => model.isdeleted)         </dt>          <dd>             @html.displayfor(model => model.isdeleted)         </dd>         </dl>       </div>        <p>         @html.actionlink("edit", "edit", new { id = model.id }) |         @html.actionlink("back list", "index")       </p> 

and survey model

            namespace surveyspaceproject.models          {     using system;     using system.collections.generic;     using system.componentmodel.dataannotations;     using system.componentmodel.dataannotations.schema;     using system.data.entity.spatial;      public partial class survey     {         [system.diagnostics.codeanalysis.suppressmessage("microsoft.usage", "ca2214:donotcalloverridablemethodsinconstructors")]         public survey()         {             surveyanswers = new hashset<surveyanswer>();             surveyquestions = new hashset<surveyquestion>();             //surveyusers = new hashset<surveyuser>();         }          public int id { get; set; }          public int userid { get; set; }          [required]         [stringlength(150)]         public string title { get; set; }          [column(typename = "date")]         public datetime? createddate { get; set; }          public bool isdeleted { get; set; }          [system.diagnostics.codeanalysis.suppressmessage("microsoft.usage", "ca2227:collectionpropertiesshouldbereadonly")]         public virtual icollection<surveyanswer> surveyanswers { get; set; }          [system.diagnostics.codeanalysis.suppressmessage("microsoft.usage", "ca2227:collectionpropertiesshouldbereadonly")]         public virtual icollection<surveyquestion> surveyquestions { get; set; }          public virtual user user { get; set; }          [system.diagnostics.codeanalysis.suppressmessage("microsoft.usage", "ca2227:collectionpropertiesshouldbereadonly")]         public virtual icollection<surveyuser> surveyusers { get; set; }     } } 

you have 2 issues:

issue 1

the partial class , model passing view in namespace namespace surveyspaceproject.models survey query returns in namespace. therefore different types. make sure nameplates same. error indicates.

issue 2

you have eagerly load user property. use include this:

var s = sspentity.getdb().surveys.include(x =>        x.user).firstordefault(x => x.id == id); 

now ef generate query user info included in query well.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -