c# - How to execute a where clause in this scenario? -


dbo.images - table http://imgur.com/g1suotj

image.cs

 public class image         {             public int id { get; set; }             public string imagepath { get; set; }             public string category { get; set; }         }         public class imagedbcontext : dbcontext         {             public dbset<image> images { get; set; }         }     } 

imagecontroller.cs

public class imagecontroller : controller {     private imagedbcontext db = new imagedbcontext();         public actionresult index(int imageid)     {         return view(db.images.where(img => img.id == imageid).tolist());     } 

index.cshtml

 @model ienumerable<mvcmovie.models.image>      @{         viewbag.title = "index"; }     <img src="~/images/@html.displayfor(imagepath.where(imageid == 2))" /> 

with reference code above i'm trying display imagepath table selecting related id. having @html.displayfor retrieving , viewing image 'imagepath' where id valued 2 or 3 or 4. working able input url stored image database onto <img src=""/> on .cshtml individually. below code isn't displaying image id valued 2.

 <img src="~/images/@html.displayfor(imagepath.where(imageid == 2))" /> 

any ideas?

highly appreciate , time.

you getting wrong think.

@html.displayfor should provide html code display model/property pass it.

what need below.

<img src="~/images/@(model.first(x=> x.id == 2).imagepath)" /> 

this throw error if no item returned.

you limiting returned controller specific id , image can displayed.

be sure id passed controller 2

alternatively can use whatever image returned ... see below.

<img src="~/images/@(model.first().imagepath)" /> 

if want contoller return images, see below.

   public actionresult index(int imageid)     {         return view(db.images.tolist());     } 

Comments