views:

217

answers:

1

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>
+1  A: 

Is this right?

Inherits="ProviderFeedback.Index"

Shouldn't that be Form.Index?

Craig Stuntz
That's what VS put in there. If I try to change it, I get a conflict in the ProviderFeedback namespace. Can I not have views named the same in different folders? From the class view, it appears that all views a grouped under the project namespace, regardless of folder.
gfrizzle
You can have views named the same in different folders if they're in different namespaces. By default, the namespace = the folder name + . + View name. This does explain your problem, BTW.
Craig Stuntz
Odd that VS wouldn't take care of that automatically - it's only using the project name and view name. I did originally create the project using the beta, so I wonder if there's something funny going on between the two. I'll try a fresh version and see what happens. Thanks for your help.
gfrizzle