【发布时间】:2011-01-19 00:25:52
【问题描述】:
我有一个带有母版页的视图。用户控件使用模型:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BudgieMoneySite.Models.SiteUserLoginModel>" %>
此用户控件显示在所有屏幕上(母版页的一部分)。如果用户已登录,它会显示一个特定的文本,如果用户未登录,它会提供一个登录框。
一切正常。
现在,我正在添加我的第一个功能屏幕。所以我创建了一个新视图……嗯,当我选择控制器方法并说“创建视图”时,我为我生成了基本视图代码。
我的控制器有这个代码:
public ActionResult Transactions()
{
List<AccountTransactionDetails> trans = GetTransactions();
return View(trans);
}
private List<AccountTransactionDetails> GetTransactions()
{
List<AccountTransactionDto> trans = Services.TransactionServices.GetTransactions();
List<AccountTransactionDetails> reply = new List<AccountTransactionDetails>();
foreach(var t in trans)
{
AccountTransactionDetails a = new AccountTransactionDetails();
foreach (var line in a.Transactions)
{
AccountTransactionLine l = new AccountTransactionLine();
l.Amount = line.Amount;
l.SubCategory = line.SubCategory;
l.SubCategoryId = line.SubCategoryId;
a.Transactions.Add(l);
}
reply.Add(a);
}
return reply;
}
所以,我的观点是这样生成的:
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<System.Collections.Generic.List<BudgieMoneySite.Models.AccountTransactionDetails>>" %>
找到 个事务。
我现在只想显示我将要显示的记录数。
当我运行它时,我得到一个错误:
“传入字典的模型项的类型为‘System.Collections.Generic.List`1[BudgieMoneySite.Models.AccountTransactionDetails]’,但此字典需要‘BudgieMoneySite.Models.SiteUserLoginModel’类型的模型项。 "
看起来用户控件首先被渲染,并且控制器中的模型是我的列表,它正在破坏!
我做错了什么?
【问题讨论】:
标签: c# asp.net-mvc master-pages