Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Oct 23, 2008 12:43 AM by tgmdbm
Oct 22, 2008 06:25 PM|LINK
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.
Dim dataContext = New PATSimDataContext()
Dim deletedvisits = From v In dataContext.VisitAudits Select v
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">
<% For Each v As VisitAudit In ViewData.deletedvisits%>
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?
Oct 23, 2008 12:43 AM|LINK
firstly, From v In dataContext.VisitAudits Select v is the same as just saying
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;
For Each v As VisitAudit In ((IEnumerable<VisitAudit>) ViewData.["deletedvisits"]