ASP.NET MVC (VB) error when publishing to test server
Posted
by Colin
on Stack Overflow
See other posts from Stack Overflow
or by Colin
Published on 2010-04-15T16:00:02Z
Indexed on
2010/04/15
16:03 UTC
Read the original article
Hit count: 227
asp.net-mvc
|vb.net
I have an ASP.NET MVC project that works fine on my local machine (no build errors, server errors or anything). However, when I publish the project to a test server, I get an "Object reference not set to an instance of an object" error on a For Each
I have in my view.
I have a function within a model that returns a DataRowCollection. I'm calling that function in my controller and passing the DataRowCollection to my View, which then iterates over the rows and displays the necessary information:
In the Controller I have:
Function Index() As ActionResult
Dim MyModel As New Model
ViewData("MyDataRowCollection") = MyModel.GetDataRowCollection()
Return View()
End Function
And then in the View, which is throwing the error:
<%@ Page Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
My Page Title
</asp:Content>
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
<%
For Each MyDataRow In ViewData("MyDataRowCollection")
' do stuff with each MyDataRow
Next
%>
I'm pretty new to ASP.NET MVC so I'm sure there might be a better way to do what I'm doing (I'd be happy to hear if there is), but my main concern is why this works fine on my local machine but throws an error on the For Each
on the test server?
Please let me know if I can clarify any of the above, and thanks in advance for any information.
© Stack Overflow or respective owner