Tuesday, April 5, 2011

asp.net mvc view strongly typed with PagedList(of product) vb.net

i have this controller function

Public Function Index(ByVal id As System.Nullable(Of Integer)) As ActionResult 
using db = New DbDataContext() 
Dim prod As PagedList(Of product) = db.products.ToPagedList(If(id, 1), 20) 
Return View(prod) 
End Using
End Function

i have to create a view strongly typed with Dim prod As PagedList(Of product)

<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage(PagedList(Of product))" %>

where is mystake?

From stackoverflow
  • For starters, your Page Inherit looks a little off. Here's one of mine.

    Inherits="System.Web.Mvc.ViewPage(Of MyProject.Domain.User)"
    

    Where Domain.User is a class created by LINQ in my DBML.

    Then in my controller I have

    Function Details(ByVal id As Integer) As ActionResult
        Dim user As Domain.User = UserService.GetUserByID(id)
        user.LastSeen = (From am In user.ActivityLogs
                            Select am.ActivityDate
                            Order By ActivityDate Descending).FirstOrDefault
    
        If Not user Is Nothing Then
    
            Return View(user)
        Else
            Response.StatusCode = CInt(HttpStatusCode.NotFound)
            Return RedirectToAction("NotFound", "Error")
        End If
    
    End Function
    
    Massimo : look at object returns to view it is Dim prod As PagedList(Of product)
  • Try changing your page definition:

    <%@ Page 
        Title="" 
        Language="VB" 
        MasterPageFile="~/Views/Shared/Site.Master" 
        Inherits="System.Web.Mvc.ViewPage(Of Webdiyer.WebControls.Mvc.PagedList(Of Paging.product))" %>
    
    Massimo : thanks now i see collections and can cicle it

0 comments:

Post a Comment