I have an import page with a dynamic number of transactions. For each transactions, I have several plain text data labels and one DropDownList (Categories). I'm trying to populate this Category DropDownList with data from my ViewModel (Categories) by passing the Categories Model as additionalViewData to my EditorTemplate.
When I use the example below, I get the following error on the EditorTemplate page: Compiler Error Message: CS0411: The type arguments for method 'System.Web.Mvc.Html.SelectExtensions.DropDownListFor(System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression>, System.Collections.Generic.IEnumerable)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
Any ideas on how to fix this?
ViewModel:
public class ImportViewModel
{
public List<AbnAmroTransaction> AbnAmroTransactions { get; set; }
public IEnumerable<SelectListItem> Categories { get; set; }
}
Model:
public class AbnAmroTransaction
{
public string Currency { get; set; }
public int DateTime { get; set; }
public string Description { get; set; }
public int CategoryId { get; set; }
}
Form:
@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" />
}
EditorTemplate:
<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>