我在我的Web应用程序上遇到HttpException,我无法修复。我正在使用.NET WebForms,实体框架和Identity Framework。这里是我运行页面时出现的错误的堆栈跟踪:
[HttpException (0x80004005): Could not load type 'Scheduler.Models.PatientModel.Patient'.]
System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +9898205
System.Web.UI.WebControls.ModelDataSourceView.get_ModelType() +62
System.Web.UI.WebControls.ModelDataSourceView.EvaluateSelectMethodParameters(DataSourceSelectArguments arguments, ModelDataSourceMethod method, Boolean isAsyncSelect, DataSourceSelectResultProcessingOptions& selectResultProcessingOptions) +115
System.Web.UI.WebControls.ModelDataSourceView.EvaluateSelectMethodParameters(DataSourceSelectArguments arguments, DataSourceSelectResultProcessingOptions& selectResultProcessingOptions) +17
System.Web.UI.WebControls.ModelDataSourceView.GetSelectMethodResult(DataSourceSelectArguments arguments) +62
System.Web.UI.WebControls.ModelDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +15
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +22
System.Web.UI.WebControls.ModelDataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +80
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
System.Web.UI.WebControls.GridView.DataBind() +9
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +114
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75
System.Web.UI.Control.EnsureChildControls() +92
System.Web.UI.Control.PreRenderRecursiveInternal() +42
System.Web.UI.Control.PreRenderRecursiveInternal() +160
System.Web.UI.Control.PreRenderRecursiveInternal() +160
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4775
当我尝试加载在aspx文件中包含此标记的Patients.aspx页面时,会发生这种情况:
<form id="form1" runat="server">
<div>
<asp:GridView ID="patientsGridView" runat="server" ItemType="Scheduler.Models.PatientModel.Patient" DataKeyNames="PatientID"
SelectMethod="patientsGridView_GetData" AutoGenerateColumns="false">
<Columns>
<asp:DynamicField DataField="LastName" />
<asp:DynamicField DataField="FirstName" />
<asp:DynamicField DataField="NickName" />
<asp:DynamicField DataField="PhoneNumber" />
</Columns>
</asp:GridView>
</div>
</form>
那个aspx页面的代码背后是:
public partial class Patients : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public IQueryable<PatientModel.Patient> patientsGridView_GetData()
{
ApplicationDbContext db = new ApplicationDbContext();
var query = db.Patients.Where(p => p.Doctor.Id == User.Identity.GetUserId());
return query;
}
}
有关如何修复该异常的任何想法?
答案 0 :(得分:0)
我错误地将我的病人模型放在另一个班级中,这导致了失败。
答案 1 :(得分:0)
我想如果其他人发现这个例外就澄清一点。
示例背后的代码中缺少的是显示患者对象的完整命名空间。
所以举个例子。具有完整命名空间的患者对象可能是
Scheduler.PatientModel.Patient
问题是,在网格上,您将ItemType设置为Scheduler.Models.PatientModel.Patient
类型的对象,而不是Scheduler.PatientModel.Patient
指向正确的对象将修复它。在此示例中,您必须将标记更改为
ItemType="Scheduler.PatientModel.Patient"
希望这有帮助