c# - Error with partial view -


i working in blog web site project. create partial view blog post.

İt's _maincontent partial view

@model system.collections.generic.ienumerable<blog.data.model.article>  @foreach (var item in model) { <div class="panel">     <div class="panel-body">         <div>             <h3>                 @html.actionlink(item.articletitle, "index", "article", new { id = item.articleid }, new { })             </h3>         </div>         <div id="img">             <img width="400" height="300" src="@string.format("data:{0};base64,{1}",item.articleimages.firstordefault().contenttype,convert.tobase64string(item.articleimages.firstordefault().content))" />         </div>         <div>             <p>                 @html.displayfor(x=> item.content)             </p>         </div>      </div> </div> } 

and it's index page

@model system.collections.generic.ienumerable<blog.data.model.article> @{ viewbag.title = "anasayfa"; }  <div class="container"> <div class="col-md-offset-10 col-md-2">     @html.partial("_sidemenupartial") </div>  <div class="col-md-10">     @html.partial("_maincontent", model.firstordefault()) </div> </div> 

when started program happen

an exception of type 'system.invalidoperationexception' occurred in system.web.mvc.dll not handled in user code  additional information: model item passed dictionary of type 'system.data.entity.dynamicproxies.article_e29cf5fdd5b2d2829b35531643263744339081c99736858ce61ddb0981d557ee', dictionary requires model item of type 'system.collections.generic.ienumerable`1[blog.data.model.article]'. 

and have empty page.

the view expecting collection of article objects:

@model system.collections.generic.ienumerable<blog.data.model.article> 

you're passing single article object:

@html.partial("_maincontent", model.firstordefault()) 

instead, provide view collection it's expecting:

@html.partial("_maincontent", model) 

(or subset of collection, still ienumerable<article>)


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -