How to display Linq to Entity query result in ASP.NET MVC view?

If you want strongly-typed objects to use in your view you would need to go into your view and change the top from %@ Page Language="VB" MasterPageFile="~/Views/Shared/Site. Master" Inherits="System.Web.Mvc. ViewPage" % to %@ Page Language="VB" MasterPageFile="~/Views/Shared/Site.

Master" Inherits="System.Web.Mvc. ViewPage(Of IEnumerable(Of String))" % Of course replacing Of String with your model type you want to pass in. To pass in your collection you would use Return View(query.ToList()) assuming query was some sort of IQueryable query from ADO.NET EF Then in your view you could iterate through the results passed in % For Each s As String In Model %.

If you want strongly-typed objects to use in your view you would need to go into your view and change the top from...\ to Of course replacing Of String with your model type you want to pass in. To pass in your collection you would use... Return View(query.ToList()) ... assuming query was some sort of IQueryable query from ADO. NET EF.

Then in your view you could iterate through the results passed in. That would output each string in the collection passed into the view's data model. Though I do recommend for best practices to create a type specifically for passing into your views, aka ViewData.

First it looks like your query is messed up a tiny bit. I am unsure about VB. NET but you would in this case need a separate class because you are selecting something that is not your Entity Framework model.

Dim var = From c In context. Evaluation_Template . Include("Assigned_Evaluation") .

Include("User_Assignment") Select c This is the third eidt, I keep posting it :) What your view page then needs to take is: IEnumerable You do this either by generating a strongly typed view or setting it in the page directive of the view page. You could also do what you are trying for (less overhead) but then you would need a separate class to send to the view page.

Thanks for your help. Do you think you can post example code of how to iterate through the result? – CoolGravatar Apr 29 '09 at 20:05 See below for a bit of URL1 magic.

I would still urge you to create new view and select strongly typed view and then ModelName. Evaluation_Template as the type. Thats the best guide you will get.

– mhenrixon May 1 '09 at 1:12.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions