I have the following view that I've developed (using VS 2010 ASP.NET MVC4) as a dashboard of sorts that has four different partial views that it renders for management:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Manager.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
AMS Utility - Manager Home Page
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="FeaturedContent" runat="server">
<section class="featured">
<div class="content-wrapper">
<hgroup class="title">
<h1>AMS Utility - Property Tax Manager's Dashboard</h1>
</hgroup>
</div>
</section>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<% Html.RenderAction("IndexTopImports"); %>
<% Html.RenderAction("IndexTopXfrReqs"); %>
<% Html.RenderAction("IndexBURequests"); %>
<% Html.RenderAction("IndexTopCompanyRequests"); %>
</asp:Content>
Here is one of the controller actions associated with the RenderAction above (all work the same way: (1) Get the data from a DTO; (2) Return the partial view with the data):
[ChildActionOnly]
public PartialViewResult IndexTopImports()
{
ManagersDashboardDTO importDTO = new ManagersDashboardDTO();
return PartialView("IndexTopImports", importDTO.GetImportList());
}
Here is one of the partial views (IndexTopImports.ascx) that is called. The format for all are all the same in that I pass to the view a list of data to be displayed:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<AMSUtilityMVC4.ViewModels.MgrsDashboardActiveImportsViewModel>>" %>
<h2 style="color:Green">Most Recent State Imports</h2>
<table>
<colgroup>
<col span="1", style="width:25%;">
<col span="1", style="width:35%;">
<col span="1", style="width:35%;">
</colgroup>
<tr>
<th>
State
</th>
<th>
Import Date
</th>
<th>
Imported By
</th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td>
<%: item.stateAcronym %>
</td>
<td>
<%: item.importDate %>
</td>
<td>
<%: item.importedBySOEID %>
</td>
</tr>
<% } %>
</table>
When I run this application locally it works just fine but when I upload it to IIS, I am getting a [NullReferenceException: Object reference not set to an instance of an object]. Here is the stack trace:
[NullReferenceException: Object reference not set to an instance of an object.] AMSUtilityMVC4.Models.MgrDashboardTopXfrRequestsDataContext..ctor() in C:\Visual Studio Projects\AMSUtilityMVC4\AMSUtilityMVC4\Models\MgrDashboardTopXfrRequests.designer.cs:38 AMSUtilityMVC4.Models.Data_Transfer_Objects.ManagersDashboardDTO..ctor() in C:\Visual Studio Projects\AMSUtilityMVC4\AMSUtilityMVC4\Models\Data Transfer Objects\ManagersDashboardDTO.cs:12 AMSUtilityMVC4.Controllers.ManagersController.IndexTopImports() in C:\Visual Studio Projects\AMSUtilityMVC4\AMSUtilityMVC4\Controllers\ManagersController.cs:73 lambda_method(Closure , ControllerBase , Object[] ) +78 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +247 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +38 System.Web.Mvc.Async.<>c__DisplayClass39.b__33() +124 System.Web.Mvc.Async.<>c__DisplayClass4f.b__49() +452 System.Web.Mvc.Async.<>c__DisplayClass37.b__36(IAsyncResult asyncResult) +15 System.Web.Mvc.Async.<>c__DisplayClass2a.b__20() +31 System.Web.Mvc.Async.<>c__DisplayClass25.b__22(IAsyncResult asyncResult) +230 System.Web.Mvc.<>c__DisplayClass1d.b__18(IAsyncResult asyncResult) +28 System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +20 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53 System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +20 System.Web.Mvc.<>c__DisplayClass8.b__3(IAsyncResult asyncResult) +42 System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +20 System.Web.Mvc.<>c__DisplayClass4.b__3() +15 System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Func1 func) +41 System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +1443
[HttpException (0x80004005): Error executing child request for handler System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper.] System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +2515 System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) +242 System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +94 System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) +693 System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues) +56 ASP.views_managers_index_aspx.__RenderContent2(HtmlTextWriter __w, Control parameterContainer) in c:\inetpub\wwwroot\AMSUtility\Views\Managers\Index.aspx:23 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +131 ASP.views_shared_manager_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\inetpub\wwwroot\AMSUtility\Views\Shared\Manager.Master:54 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +131 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +246 System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +85 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5290
Short of rewriting the view to not use partial views, I'm at a lost as to how to fix this challenge. Any ideas or suggestions?
<asp:
and/or containsrunat="server"
are not designed with MVC (they are legacy Webforms tags). I highly recommend not using them ever, they are not needed. – Erik Philips