我正在返回多個形狀到一個頁面,並使用我創建的ViewData類。這個類的命名空間是:繼承多個形狀 - ASP.NET MVC
namespace IntranetMvcAreas.Areas.Accounts.Views.ContractsControl.ViewData
我不確定它是否正確。在頁面我試圖:
Inherits="System.Web.Mvc.ViewPage<ViewData.ContractsViewData>"
但ViewData
甚至沒有在智能感知解決,所以我不知道我做錯了,但我不能讓任何可用對象的訪問。
我也這樣做的控制器功能:
return View(new ContractsViewData(contracts, costCentres, userTerminals, serviceMapping, services));
應提供在視圖中的ViewData對象。
任何想法?
編輯
這裏是我的命名空間導入我的web.config
<namespaces>
<add namespace="IntranetMvcAreas.Areas.Accounts.Models"/>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Linq" />
<add namespace="System.Collections.Generic" />
</namespaces>
我搬到ContractsViewData到Models文件夾,而不是現在。
UPDATE
我重新創建整個項目並建立它從零開始只是雙重檢查。我正在使用Phil Haack's AreaLib,我不確定這是否有任何區別。無論如何,我已經得到了它包含一個名爲ContractsControlViewData.cs
一個ViewData的類,它包含以下內容的文件夾的ViewModels:
namespace Intranet.Areas.Accounts.ViewModels
{
using Intranet.Areas.Accounts.Models;
using System.Collections.Generic;
public class ContractsControlViewData
{
public IEnumerable<Contract> Contracts { get; set; }
public IEnumerable<tblCC_Contract_CC> tblCC_Contract_CCs { get; set; }
public IEnumerable<tblCC_Contract_Data_Terminal> tblCC_Contract_Data_Terminals { get; set; }
public IEnumerable<tblCC_CDT_Data_Service> tblCC_CDT_Data_Services { get; set; }
public IEnumerable<tblCC_Data_Service> tblCC_Data_Services { get; set; }
}
}
然後在我的控制,我有以下:
public ActionResult DataContracts()
{
IEnumerable<Contract> contracts;
using(ContractsControlDataContext db = new ContractsControlDataContext())
{
IMultipleResults results = db.procCC_Contract_Select(null, null, null, null, null, null);
contracts = results.GetResult<Contract>();
}
return View(new ContractsControlViewData {
Contracts = contracts,
tblCC_Contract_CCs = null,
tblCC_Contract_Data_Terminals = null,
tblCC_CDT_Data_Services = null,
tblCC_Data_Services = null
});
}
我的web配置具有以下:
<namespaces>
<add namespace="Intranet.Areas.Accounts.ViewModels"/>
<add namespace="System.Web.Mvc"/>
<add namespace="System.Web.Mvc.Ajax"/>
<add namespace="System.Web.Mvc.Html"/>
<add namespace="System.Web.Routing"/>
<add namespace="System.Linq"/>
<add namespace="System.Collections.Generic"/>
</namespaces>
我ContractsControl.design.cs
具有以下(因爲如果你把它在部分類它不工作:
[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<int> contractID,
[Parameter(Name = "ContractTypeID", DbType = "Int")] System.Nullable<int> contractTypeID,
[Parameter(Name = "ResponsibilityKey", DbType = "Int")] System.Nullable<int> responsibilityKey,
[Parameter(Name = "ExpenseType", DbType = "Char(4)")] string expenseType,
[Parameter(Name = "SupplierID", DbType = "Int")] System.Nullable<int> 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;
}
一旦我將通用放置在我的Inherits語句中,我不再能夠訪問ViewData。此外,如果我將分佈式類中的聲明函數聲明放置,我無法進行構建。
所以我不知道。就我個人而言,我認爲這是一個錯誤,但後來有一個存儲過程帶回多個結果集並不是很好。事實上,這太可怕了。
編輯
我發現是相關的唯一的事情就是this link。但是,當我清除應用程序設置並將其設置爲false時,會刪除我的* .designer.cs文件,這意味着無法訪問來自我的dbml文件的類。
**編輯編輯**
之後重新實現模型(再次)和伊恩的想法將增加以下內容:
<PropertyGroup>
<MvcBuildViews>true</MvcBuildViews>
</PropertyGroup>
我現在收到以下錯誤:
Error 1 Could not load type 'System.Web.Mvc.ViewPage<ContractsControlViewData>'. D:\temp\Areas\Accounts\Views\ContractsControl\DataContracts.aspx 2 Intranet
不過,我已經試過完全合格的名字,我也試着放置在同一文件夾中查看的ViewData類以及消除命名空間,以確保它是無濟於事能夠。這是因爲某種原因沒有被看到,但至少它可能會更近一步?我猜ViewData在視圖中不可用,因爲在inherits語句中使用的泛型是無效的,這將解釋它的一部分。
任何進一步的想法?
對於我來說,更具體的問題是ViewData甚至不會出現在頁面的intellisense中。它只出現,如果我擺脫泛型類型之間< and > – Kezzer 2009-06-18 09:02:33
您是否在您的解決方案中導入了System.Web.Mvc dll? 你在你的web.config中導入了哪些命名空間? – madcapnmckay 2009-06-18 09:07:17