title: Inheriting For Multiple Shapes - ASP.NET MVC
body: <p>I'm returning multiple shapes to a page and am using a ViewData class that I've created.  The namespace of this class is:</p>
  
  <pre><code>namespace IntranetMvcAreas.Areas.Accounts.Views.ContractsControl.ViewData
  </code></pre>
  
  <p>which I'm not sure it correct.  In the page I attempted:</p>
  
  <pre><code>Inherits="System.Web.Mvc.ViewPage&lt;ViewData.ContractsViewData&gt;"
  </code></pre>
  
  <p>But <code>ViewData</code> doesn't even resolve in intellisense, so I'm not sure what I'm doing wrong, but I can't get access to any of the available objects.</p>
  
  <p>I'm also doing this in the controller function:</p>
  
  <pre><code>return View(new ContractsViewData(contracts, costCentres, userTerminals, serviceMapping, services));
  </code></pre>
  
  <p>which should provide that ViewData object in the view.</p>
  
  <p>Any ideas?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here's my namespaces import in my web.config</p>
  
  <pre><code>&lt;namespaces&gt;
      &lt;add namespace="IntranetMvcAreas.Areas.Accounts.Models"/&gt;
      &lt;add namespace="System.Web.Mvc" /&gt;
      &lt;add namespace="System.Web.Mvc.Ajax" /&gt;
      &lt;add namespace="System.Web.Mvc.Html" /&gt;
      &lt;add namespace="System.Web.Routing" /&gt;
      &lt;add namespace="System.Linq" /&gt;
      &lt;add namespace="System.Collections.Generic" /&gt;
  &lt;/namespaces&gt;
  </code></pre>
  
  <p>I've moved ContractsViewData to the Models folder instead now.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I re-created the entire project and built it up from scratch just to double check.  I'm using <a href="http://haacked.com/archive/2008/11/04/areas-in-aspnetmvc.aspx" rel="nofollow noreferrer">Phil Haack's AreaLib</a>, I'm not sure if this makes any difference.  Anyway, I've got a ViewModels folder which contains a ViewData class called <code>ContractsControlViewData.cs</code> which contains the following:</p>
  
  <pre><code>namespace Intranet.Areas.Accounts.ViewModels
  {
    using Intranet.Areas.Accounts.Models;
    using System.Collections.Generic;
  
    public class ContractsControlViewData
    {
      public IEnumerable&lt;Contract&gt; Contracts { get; set; }
      public IEnumerable&lt;tblCC_Contract_CC&gt; tblCC_Contract_CCs { get; set; }
      public IEnumerable&lt;tblCC_Contract_Data_Terminal&gt; tblCC_Contract_Data_Terminals { get; set; }
      public IEnumerable&lt;tblCC_CDT_Data_Service&gt; tblCC_CDT_Data_Services { get; set; }
      public IEnumerable&lt;tblCC_Data_Service&gt; tblCC_Data_Services { get; set; }
    }
  }
  </code></pre>
  
  <p>Then in my controller I have the following:</p>
  
  <pre><code>        public ActionResult DataContracts()
          {
            IEnumerable&lt;Contract&gt; contracts;
  
            using(ContractsControlDataContext db = new ContractsControlDataContext())
            {
              IMultipleResults results = db.procCC_Contract_Select(null, null, null, null, null, null);
              contracts = results.GetResult&lt;Contract&gt;();
            }
  
            return View(new ContractsControlViewData {
              Contracts = contracts,
              tblCC_Contract_CCs = null,
              tblCC_Contract_Data_Terminals = null,
              tblCC_CDT_Data_Services = null,
              tblCC_Data_Services = null
            });
          }
  </code></pre>
  
  <p>My web config has the following:</p>
  
  <pre><code>  &lt;namespaces&gt;
      &lt;add namespace="Intranet.Areas.Accounts.ViewModels"/&gt;
      &lt;add namespace="System.Web.Mvc"/&gt;
      &lt;add namespace="System.Web.Mvc.Ajax"/&gt;
      &lt;add namespace="System.Web.Mvc.Html"/&gt;
      &lt;add namespace="System.Web.Routing"/&gt;
      &lt;add namespace="System.Linq"/&gt;
      &lt;add namespace="System.Collections.Generic"/&gt;
    &lt;/namespaces&gt;
  </code></pre>
  
  <p>My <code>ContractsControl.design.cs</code> has the following (because it doesn't work if you place it in the partial class:</p>
  
  <pre><code>[Function(Name = "dbo.procCC_Contract_Select")]
      [ResultType(typeof(Contract))]
      [ResultType(typeof(tblCC_Contract_CC))]
      [ResultType(typeof(tblCC_Contract_Data_Terminal))]
      [ResultType(typeof(tblCC_CDT_Data_Service))]
      [ResultType(typeof(tblCC_Data_Service))]
      public IMultipleResults procCC_Contract_Select(
          [Parameter(Name = "ContractID", DbType = "Int")] System.Nullable&lt;int&gt; contractID,
          [Parameter(Name = "ContractTypeID", DbType = "Int")] System.Nullable&lt;int&gt; contractTypeID,
          [Parameter(Name = "ResponsibilityKey", DbType = "Int")] System.Nullable&lt;int&gt; responsibilityKey,
          [Parameter(Name = "ExpenseType", DbType = "Char(4)")] string expenseType,
          [Parameter(Name = "SupplierID", DbType = "Int")] System.Nullable&lt;int&gt; supplierID,
          [Parameter(Name = "BusinessID", DbType = "Char(4)")] string businessID)
      {
        IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), contractID, contractTypeID, responsibilityKey, expenseType, supplierID, businessID);
        return (IMultipleResults)result.ReturnValue;
      }
  </code></pre>
  
  <p>Once I place the generic  in my Inherits statement I no longer get access to ViewData.  Additionally if I place the sproc function declaration in the partial class I can't do a build.</p>
  
  <p>So I have got no idea.  Personally I think it's a bug, but then having a stored procedure bring back multiple result sets isn't exactly great.  In fact, it's horrible.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The only thing I found that was relevant was <a href="http://social.msdn.microsoft.com/Forums/en-US/linqprojectgeneral/thread/8c66d227-4b45-4f03-ae5a-87ba0051b953" rel="nofollow noreferrer">this link</a>.  However, when I clear out the Application Settings and set it to false my *.designer.cs file is removed which means no classes from my dbml file are accessible.</p>
  
  <p>**EDIT EDIT **</p>
  
  <p>After re-implementing the model (again) and going with Ian's idea to add the following:</p>
  
  <pre><code>&lt;PropertyGroup&gt;
      &lt;MvcBuildViews&gt;true&lt;/MvcBuildViews&gt;
  &lt;/PropertyGroup&gt;
  </code></pre>
  
  <p>I now receive the following error:</p>
  
  <pre><code>Error   1   Could not load type 'System.Web.Mvc.ViewPage&lt;ContractsControlViewData&gt;'.    D:\temp\Areas\Accounts\Views\ContractsControl\DataContracts.aspx    2   Intranet
  </code></pre>
  
  <p>However, I've tried with the fully qualified name, and I've also tried placing the ViewData class in the same folder as the View as well as removing the namespace to make sure it's available.  It's not being seen for some reason, but at least it's a step closer perhaps? I'm guessing ViewData wasn't available in the view because the generic used in the inherits statement wasn't valid, which would explain that part of it.</p>
  
  <p>Any further thoughts?</p>