【发布时间】:2012-05-20 16:59:21
【问题描述】:
我有一个包含动态交易数量的导入页面。对于每笔交易,我都有几个纯文本数据标签和一个 DropDownList(类别)。我正在尝试通过将类别模型作为附加视图数据传递给我的 EditorTemplate 来使用来自我的 ViewModel (Categories) 的数据填充此 CategoryDropDownList。
当我使用下面的示例时,我在 EditorTemplate 页面上收到以下错误: 编译器错误消息:CS0411:方法“System.Web.Mvc.Html.SelectExtensions.DropDownListFor(System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression>, System.Collections.Generic.IEnumerable)”的类型参数不能从用法推断。尝试明确指定类型参数。
关于如何解决这个问题的任何想法?
视图模型:
public class ImportViewModel
{
public List<AbnAmroTransaction> AbnAmroTransactions { get; set; }
public IEnumerable<SelectListItem> Categories { get; set; }
}
型号:
public class AbnAmroTransaction
{
public string Currency { get; set; }
public int DateTime { get; set; }
public string Description { get; set; }
public int CategoryId { get; set; }
}
表格:
@using (Html.BeginForm("ImportPreview", "Home", FormMethod.Post))
{
<table>
@Html.EditorFor(m => m.AbnAmroTransactions, new { Categories = Model.Categories });
</table>
<input id="btnSave" type="submit" value="Save data" />
}
编辑器模板:
<tr>
<td style="width: 80px;">
@Html.Raw(CurrencyHelper.GetHtmlCurrency(Model.Currency, Model.Amount))
</td>
<td>@Model.DateTime</td>
<td>@Model.Description</td>
<td>@Html.DropDownListFor(Model.CategoryId, ViewData["Categories"])</td>
</tr>
【问题讨论】:
标签: c# .net asp.net-mvc-3 drop-down-menu