title: How to show selected value in a DropDownList Html Helper using ViewBag in C#
body: <p>So I have the following scenario in which I am using two <code>ViewBag</code>(s):</p>
  <ol>
  <li>To get the select list item</li>
  <li>To get the particular item in concern</li>
  </ol>
  <p>So it looks like this:</p>
  <pre><code>var currentType = &quot;2&quot;;
  List&lt;SelectListItem&gt; contentData = new List&lt;SelectListItem&gt;();
  contentData.Add(new SelectListItem
  {
      Text = &quot;Show 0 only&quot;,
      Value = &quot;0&quot;,
  });
  
  contentData.Add(new SelectListItem
  {
      Text = &quot;Show 2 Only&quot;,
      Value = &quot;2&quot;,
  });
  
  
  ViewBag.currentType = currentType;
  ViewBag.contentData = contentData;
  </code></pre>
  <p>Now in my Razor <code>View</code>, I am able to generate the <code>DropDownList</code> like this:</p>
  <pre><code>@Html.DropDownList(&quot;ContentTypeId&quot;, (IEnumerable&lt;SelectListItem&gt;)ViewBag.contentData, null, new { @class = &quot;form-control&quot; , @style = &quot;width: 150px;&quot; })
  </code></pre>
  <p>How can I can bind my <code>ViewBag.currentType</code> on the drop down list so it shows the pre selected value by default when the component is rendered?</p>
  <p>Is it even possible to use two <code>ViewBag</code> value in this component ?</p>
  <p>I tried like this:</p>
  <pre><code>@Html.DropDownList(&quot;ContentTypeId&quot;, (IEnumerable&lt;SelectListItem&gt;)ViewBag.contentData, null, new { @class = &quot;form-control&quot; , @style = &quot;width: 150px;&quot;, @selected= (string)ViewBag.currentType})
  </code></pre>
  <p>But not getting the correct output.</p>
  <p>Any tips/suggestions/solutions?</p>