title: How to pass value selected from DropDownList to Controller - MVC
body: <p>I am having trouble getting the value selected in my dropdownlist in my Homecontroller. I have the DropDownList in a form but I think my format may be wrong. I'm new to MVC and new to HTML so I'm struggling pretty hard. Would appreciate some help.</p>
  <p>Here is my controller (I put this in my homecontroller, is that a bad idea?):</p>
  <pre class="lang-cs prettyprint-override"><code>public IActionResult Index()
  {
      _ = new List&lt;MyjsonSettings&gt;();
      var obj = new StatusPortController(configuration);
      List&lt;MyjsonSettings&gt; PortList = obj.GetPortNum();
      List&lt;SelectListItem&gt; AppNameList = PopulateDropDown(PortList);
      
      ViewData[&quot;Applications&quot;] = AppNameList;
      
      return View(&quot;~/Views/Home/dataview.cshtml&quot;);
  }
      
  public List&lt;SelectListItem&gt; PopulateDropDown(List&lt;MyjsonSettings&gt; PortList)
  {
      List&lt;SelectListItem&gt; AppNameList = new List&lt;SelectListItem&gt;();
      
      for (int i = 0; i &lt; PortList.Count(); i++)
      {
          AppNameList.Add(new SelectListItem {
              Text = PortList[i].NAME, Value = (i+1).ToString()
          });
      }
      
      return AppNameList;
  }
  </code></pre>
  <p>Here is the view (dataview.cshtml):</p>
  <pre><code>@{
     ViewData[&quot;Title&quot;] = &quot;Home Page&quot;;
  }
  
  
  @using (Html.BeginForm(&quot;Index&quot;, &quot;Home&quot;, FormMethod.Post))
  {
      @Html.DropDownList(&quot;Applications&quot;, ViewData[&quot;AppNameList&quot;] as List&lt;SelectListItem&gt;)
  
      &lt;input type=&quot;submit&quot; value=&quot;submit&quot; /&gt;
  }
  </code></pre>
  <p>Any ideas? No errors when I run, I just don't know how to get the response back.</p>