I'm trying to learn to use the ASP.Net MVC. I've been following the tutorials, which are great, but I've bumped into a problem that I'm hoping someone can help me with.
Function Index()
Dim dataContext = New PATSimDataContext()
Dim deletedvisits = From v In dataContext.VisitAudits Select v
Return View(deletedvisits)
End Function
Thats the Index function in my controller.
Here's my View:
<%@ Page Language="VB" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="false" CodeBehind="Index.aspx.vb" Inherits="PATSimRestore.Index" %>
<%@ Import Namespace="PATSimRestore" %>
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
<ul>
<% For Each v As VisitAudit In ViewData.deletedvisits%>
<li><%v.VisitDate%></li>
<% Next%>
</ul>
</asp:Content>
But I get his error when I try to build this project:
'deletedvisits' is not a member of 'System.Web.Mvc.ViewDataDictionary'.
Can someone shed some light on what I need to do to fix this?
dbuttric
0 Points
1 Post
ASP.Net MVC ViewData collection does not contain my object
Oct 22, 2008 06:25 PM|LINK
Hi,
I'm trying to learn to use the ASP.Net MVC. I've been following the tutorials, which are great, but I've bumped into a problem that I'm hoping someone can help me with.
Function Index()
Dim dataContext = New PATSimDataContext()
Dim deletedvisits = From v In dataContext.VisitAudits Select v
Return View(deletedvisits)
End Function
Thats the Index function in my controller.
Here's my View:
<%@ Page Language="VB" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="false" CodeBehind="Index.aspx.vb" Inherits="PATSimRestore.Index" %>
<%@ Import Namespace="PATSimRestore" %>
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
<ul>
<% For Each v As VisitAudit In ViewData.deletedvisits%>
<li><%v.VisitDate%></li>
<% Next%>
</ul>
</asp:Content>
But I get his error when I try to build this project:
'deletedvisits' is not a member of 'System.Web.Mvc.ViewDataDictionary'.
Can someone shed some light on what I need to do to fix this?
Thanks.
David Buttrick
tgmdbm
Contributor
4392 Points
883 Posts
ASPInsiders
MVP
Re: ASP.Net MVC ViewData collection does not contain my object
Oct 23, 2008 12:43 AM|LINK
firstly, From v In dataContext.VisitAudits Select v is the same as just saying dataContext.VisitAudits
---
Return View(deletedvisits) sets the Model property on the ViewData object to deletedvisits.
so it would be
For Each v As VisitAudit In ((IEnumerable<VisitAudit>) ViewData.Model )
unless the page derives from ViewPage<IEnumerable<VisitAudit>>, if so you don't need the cast.
---
Another way to do it is
ViewData["deletedvisits"] = deletedvisits;
Return View();
For Each v As VisitAudit In ((IEnumerable<VisitAudit>) ViewData.["deletedvisits"] )