Note that there are some explanatory texts on larger screens.

plurals
  1. POEdit doesn't work with Html.DropDownList and @class attribute
    primarykey
    data
    text
    <p>Controller:</p> <pre><code>ViewBag.Category = new SelectList(this.service.GetAllCategories(), product.Category); </code></pre> <p>I'm not using Id + Name. GetAllCategories() returns only several int numbers.</p> <p>When I use in a View:</p> <pre><code>@Html.DropDownList("Category", String.Empty) </code></pre> <p>everything works. Edit is ok and DropDownList shows the selected value. HTML result: </p> <pre><code>&lt;select id="Category" name="Category"&gt; &lt;option value=""&gt;&lt;/option&gt; &lt;option&gt;1&lt;/option&gt; &lt;option&gt;2&lt;/option&gt; &lt;option&gt;3&lt;/option&gt; &lt;option&gt;4&lt;/option&gt; &lt;option selected="selected"&gt;5&lt;/option&gt; ... &lt;/select&gt; </code></pre> <p>But I need to use css @class so I use this code:</p> <pre><code>@Html.DropDownList("Category", (IEnumerable&lt;SelectListItem&gt;)ViewBag.Category, new { @class = "anything" }) </code></pre> <p>HTML result:</p> <pre><code>&lt;select class="anything" id="Category" name="Category"&gt; &lt;option&gt;1&lt;/option&gt; &lt;option&gt;2&lt;/option&gt; &lt;option&gt;3&lt;/option&gt; &lt;option&gt;4&lt;/option&gt; &lt;option&gt;5&lt;/option&gt; ... &lt;/select&gt; </code></pre> <p>Unfortunately, Edit still works (I can save the value that I select) but <strong>DropDownList starts to show the default value not the value saved in the database</strong>.</p> <p>Do you have any ideas what would be the problem?</p> <p><strong>Update</strong> I made an update to be more precise.</p> <p>The method GetAllCategories looks like this:</p> <pre><code>public List&lt;int&gt; GetAllCategories() { List&lt;int&gt; categories = new List&lt;int&gt;() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; return categories; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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