views:

24

answers:

2

Controller action:

public ActionResult Index()
    {
        probaEntities proba = new probaEntities();
        probaEntities proba1 = new probaEntities();
        probaEntities proba2 = new probaEntities();

        var query = from i in proba.name
                   from j in proba1.id_person
                   from k in proba2.last_name
                   select new
                   {
                       i.ime,
                       j.id,
                       k.prezime
                   };
        return View(query);
    }

View page:

<%@ Control Language="C#" Inherits="???" %>

<table>
       <tr>

        <th>
            ime
        </th>
         <th>
            broj
        </th>
         <th>
            prezime
        </th>
    </tr>

<% foreach (var item in Model) { %>

    <tr>

        <td>
            <%= Html.Encode(item.name) %>
        </td>
        <td>
            <%= Html.Encode(item.id_person)%>
        </td>
        <td>
            <%= Html.Encode(item.last_name)%>
        </td>
    </tr>

<% } %>

</table>

What to write in Inherits="???" ? This View is not strongly typed because I have post data to him from 3 tables. Do I have to make a special model for this view is there a shorter solution?

+1  A: 

You can use

<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
RedFilter
In that case I have this error: foreach statement cannot operate on variables of type 'object' because 'object' does not contain a public definition for 'GetEnumerator'
Ognjen
If you want to enumerate, you can create your own class that represents your data model and implement IEnumerable. Then you would use `Inherits="System.Web.Mvc.ViewPage<MyClass>"`, passing that into the view from the controller of course.
RedFilter
Can do that without my own class who is represent data model
Ognjen
when I write <%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage" %> i have this error: Compiler Error Message: CS1579: foreach statement cannot operate on variables of type 'object' because 'object' does not contain a public definition for 'GetEnumerator'
Ognjen
+1  A: 

You can't pass an anonymous type as a generic type argument unless you want to implement System.Web.Mvc.ViewPage<dynamic> - and then code your view to hope for the best. (also required you to be using .NET 4!)

Creating a strong typed view model is probably going to be your best bet though.

Tejs
In the end I though make data model. I using .NET 3.5
Ognjen