Note that there are some explanatory texts on larger screens.

plurals
  1. PODB filled DropDownList in EditorTemplate
    text
    copied!<p>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 <code>Category</code> DropDownList with data from my ViewModel (<code>Categories</code>) by passing the Categories Model as additionalViewData to my EditorTemplate.</p> <p>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.</p> <p>Any ideas on how to fix this?</p> <p>ViewModel:</p> <pre><code>public class ImportViewModel { public List&lt;AbnAmroTransaction&gt; AbnAmroTransactions { get; set; } public IEnumerable&lt;SelectListItem&gt; Categories { get; set; } } </code></pre> <p>Model:</p> <pre><code>public class AbnAmroTransaction { public string Currency { get; set; } public int DateTime { get; set; } public string Description { get; set; } public int CategoryId { get; set; } } </code></pre> <p>Form:</p> <pre><code>@using (Html.BeginForm("ImportPreview", "Home", FormMethod.Post)) { &lt;table&gt; @Html.EditorFor(m =&gt; m.AbnAmroTransactions, new { Categories = Model.Categories }); &lt;/table&gt; &lt;input id="btnSave" type="submit" value="Save data" /&gt; } </code></pre> <p>EditorTemplate:</p> <pre><code>&lt;tr&gt; &lt;td style="width: 80px;"&gt; @Html.Raw(CurrencyHelper.GetHtmlCurrency(Model.Currency, Model.Amount)) &lt;/td&gt; &lt;td&gt;@Model.DateTime&lt;/td&gt; &lt;td&gt;@Model.Description&lt;/td&gt; &lt;td&gt;@Html.DropDownListFor(Model.CategoryId, ViewData["Categories"])&lt;/td&gt; &lt;/tr&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload