MVC调用默认的页面打开不同的网页是什么时候?
-
20-08-2019 - |
题
我有一个简单的MVC(RC1)的应用程序设置,并且我看到一些奇怪的行为。家庭/索引页面显示了使用一个ListView项的列表。这里的HomeController的代码:
Function Index()
ViewData("results") = From m In context.MyTable
Return View()
End Function
在首页/的Index.aspx页面只是上有一个ListView,而后面的代码中有这样的:
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
MyListView.DataSource = ViewData("results")
MyListView.DataBind()
End Sub
该导航首页/索引时工作正常。但是,我有另外的看法,控制器称为表。这只是一个存根现在,所以这里的的FormController:
Function Index()
Return View()
End Function
在窗体/ Index.aspx的没有后面的代码 - 再次,只是一个存根
我看到的问题是,当我尝试浏览到表格/索引,我得到“未将对象引用设置到对象的实例。”家用/ Index.aspx.vb背后的代码。为什么是这样?我试图导航到其它页面了 - 为什么它试图后面执行的代码?如果我包裹这样的代码:
If ViewData("results") IsNot Nothing Then
MyListView.DataSource = ViewData("results")
MyListView.DataBind()
End If
一切工作正常,但它似乎并不像我应该这样做。我缺少的东西吗?
更新:每请求,这里的窗体/的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>
解决方案
这是正确?
Inherits="ProviderFeedback.Index"
应该不是被Form.Index?
不隶属于 StackOverflow