title: mvc4 dropdownlistfor set value from 0 to available stock
body: <p>I want to display a dropdownlist in mvc4 razor view which will have values depending from the items in stock. 
  This is the view I have:</p>
  
  <pre><code>@using (Html.BeginForm())
  {
         &lt;div class="panel-group"&gt;                   
      @foreach (var m in Model)
      {
          &lt;div class="panel panel-default"&gt;
              &lt;div class="panel-heading"&gt;
                  &lt;h4 class="panel-title"&gt;
                      &lt;a data-toggle="collapse" id="#accordion" data-parent="#accordion" href="#@m.Categories.ID.ToString()"&gt;
                          @m.Categories.Name &lt;span class="badge"&gt;@m.Categories.ItemCount&lt;/span&gt;
                      &lt;/a&gt;                     
                  &lt;/h4&gt;
              &lt;/div&gt;
              &lt;div id="@m.Categories.ID.ToString()" class="panel-collapse collapse"&gt;                
                  &lt;div class="panel-body"&gt;
                      &lt;ul class="list-group"&gt;
                          @foreach (var i in m.Items)
                          {                            
                                  using (Html.BeginForm("AddToCart", "Cart"))
                                  {
                              &lt;li class="list-group-item"&gt;
                                  @i.Name | Price £@i.Price                               
  
                                  &lt;div class="pull-right"&gt;
  
                                      &lt;input type="submit" class="btn btn-success" id="addButton" style="margin-bottom: 5px;" value="Add"/&gt;                                                                                                                       
                                      @Html.Hidden("ItemId", @i.Id)
                                      @Html.Hidden("categoryId", @m.Categories.ID)
                                      @Html.Hidden("returnUrl", Request.Url.PathAndQuery)                                        
                                  &lt;/div&gt;                              
                              &lt;/li&gt;                            
                                }
                          }
                      &lt;/ul&gt;  
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;         
      }        
  &lt;/div&gt;                                  
  }
  </code></pre>
  
  <p>Now, for each item in m.Items, there's a property called Stock, so in the view, I want to have some kind of dropdown with values from 0 to Stock value for each item. Any idea how I can populate that specific dropdownlist?</p>
  
  <h2>Update</h2>
  
  <p>This is what I'm doing:</p>
  
  <p>In the viewmodel I'm adding one more property:</p>
  
  <pre><code>  public List&lt;SelectListItem&gt; StockSelectList;
  </code></pre>
  
  <p>In the controller I'm setting the property:</p>
  
  <pre><code>            List&lt;SelectListItem&gt; itemsInStockSelectList = new List&lt;SelectListItem&gt;();           
              for (int x = 0; x &lt; itemsList.Items.Count; x++)
              {
                  var selectItem = new SelectListItem();
                  selectItem.Text = itemsList.Items[x].InStockNow.ToString();
                  selectItem.Text = itemsList.Items[x].InStockNow.ToString();
                  itemsInStockSelectList.Add(selectItem);                
              }
  </code></pre>
  
  <p>Using this approach I'm setting the values but I need to set for each item in the category, maybe I can use one more property to get the categoryID and the itemID for the SelectItemList?</p>
  
  <p>And in the view I tried this approach:</p>
  
  <pre><code> @Html.DropDownListFor(k =&gt; i.InStockNow, m.StockSelectList)
  </code></pre>
  
  <p>And as I said I'm getting same values for all the items. </p>