I've got a simple MVC (RC1) app set up, and I'm seeing some odd behavior. The Home/Index page shows a list of items using a ListView. Here's the HomeController code:
Function Index()
ViewData("results") = From m In context.MyTable
Return View()
End Function
The Home/Index.aspx page just has a ListView on it, and the code behind has this:
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
MyListView.DataSource = ViewData("results")
MyListView.DataBind()
End Sub
This works fine when navigating to Home/Index. However, I've got another view and controller called Form. It's just a stub right now, so here's the FormController:
Function Index()
Return View()
End Function
The Form/Index.aspx has no code behind - again, just a stub.
The problem I'm seeing is that when I try to navigate to Form/Index, I get "Object reference not set to an instance of an object." on the code behind of Home/Index.aspx.vb. Why is this? I'm trying to navigate away from that page - why is it trying to execute the code behind? If I wrap the code like this:
If ViewData("results") IsNot Nothing Then
MyListView.DataSource = ViewData("results")
MyListView.DataBind()
End If
everything functions correctly, but it doesn't seem like I should have to do that. Am I missing something?
Update: Per request, here's the contents of Form/Index.aspx:
<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="false" CodeBehind="Index.aspx.vb" Inherits="ProviderFeedback.Index" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<h3>
Enter Provider Feedback
</h3>
<form method="post" action="/Form/CreateNew">
<%=Html.TextBox("member")%>
<input type="submit" value="Submit" />
</form>
</asp:Content>