我有一个包含动态交易数量的导入页面。对于每笔交易,我都有几个纯文本数据标签和一个 DropDownList(类别)。我试图通过将类别模型作为附加视图数据传递给我的 EditorTemplate,Category
用我的 ViewModel () 中的数据填充这个 DropDownList 。Categories
当我使用下面的示例时,我在 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>