c# - use viewdata.model to send db query to a view -



c# - use viewdata.model to send db query to a view -

i want utilize viewdata.model send query result view. model requires model item of type ienumerable.

private rscontextsansedm db = new rscontextsansedm(); viewdata.model = (from in db.tmembresansedmdb bring together b in db.dbtassociation on a.idassociation equals b.idassociation a.idassociation == listemembre.idassociation select new { }); homecoming view();

there error @ execution.

the model item passed dictionary of type 'system.data.entity.infrastructure.dbquery1[<>f__anonymoustype31[rstestsansedm.‌​models.tmembre]]', dictionary requires model item of type 'system.collections.generic.ienumerable`1[rstestsansedm.models.tmembre]'

and model :

namespace rstestsansedm.models { public partial class tmembre { [key] public int idmembre { get; set; } public string nommembre { get; set; } public string prenommembre { get; set; } public string mailmembre { get; set; } public string srcimage { get; set; } public int idassociation { get; set; } //public virtual ienumerable<tmembre> membreassociation { get; set; } }

and view :

@model ienumerable<rstestsansedm.models.tmembre> @foreach (var item in model) { <div class="divmembre"> <div class="dphoto"><img src="~/content/@item.srcimage"/></div>

help please :)

this line

select new { });

is creating anonymous object. alter to

viewdata.model = (from in db.tmembresansedmdb bring together b in db.dbtassociation on a.idassociation equals b.idassociation a.idassociation == listemembre.idassociation select a);

c# asp.net-mvc

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -