Ognjen
Ognjen

Reputation: 1195

not strongly typed view problem

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:

<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?

Upvotes: 0

Views: 270

Answers (2)

Tejs
Tejs

Reputation: 41246

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.

Upvotes: 1

D&#39;Arcy Rittich
D&#39;Arcy Rittich

Reputation: 171421

You can use

<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage" %>

Upvotes: 1

Related Questions