title: Posting a null validation from drop down list MVC
body: <p>I am working to develop an application asp.net MVC that has a text box and two drop down lists. Users can input a numeric value and choose from the list from - to to process . My problem is trying to validate the drop down list as I tried to use the required validation but didn't work. I also tried to check on the drop downs when sending null values but the error validation doesn't work!</p>
  
  <p>The error type:</p>
  
  <pre><code>There is no ViewData item of type 'IEnumerable&lt;SelectListItem&gt;' that has the key 'fromCurrency.Name'.
  </code></pre>
  
  <p>Contorller </p>
  
  <pre><code> [HttpPost]
          public ActionResult Index(Currencies cur)
          {
              if (ModelState.IsValid)
              {
  
  
  
                  if (String.IsNullOrWhiteSpace(cur.fromCurrency.Name) || String.IsNullOrWhiteSpace(cur.toCurrency.Name))
                  {
                      ModelState.AddModelError(string.Empty, "you can not leave the empty dropdown please select any of these");
                  }
  
  
                  else
                  {
  
                      var fromCurrencyList = CurrenciesClient.GetFromCurrencyListAsync().Result;
  
                      ViewBag.FromCurrencies = new SelectList(fromCurrencyList, "CurrencyCode", "Name");
  
                      var ToCurrencyList = CurrenciesClient.GetToCurrencyListAsync().Result;
  
                      ViewBag.ToCurrencies = new SelectList(ToCurrencyList, "CurrencyCode", "Name");
  
  
                      var fromcurrname = cur.fromCurrency.Name;
                      string tocurrname = cur.toCurrency.Name;
  
                      //rate is taking by passing both dropdown currency code
                      decimal rate = CurrenciesClient.GetConversionRate("Currencies/GetConversionRate?fromcurrname=" + fromcurrname + "&amp;tocurrname=" + tocurrname).Result;
                      ViewBag.TheResult = cur.CurrencyToConvert * rate;
  
  
                  }
  
              }
              return View();
          }
  </code></pre>
  
  <p>Index View</p>
  
  <pre><code>@model ViewModel.Currencies
  
  @{
      ViewBag.Title = "Index";
  }
  
  &lt;script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"&gt;&lt;/script&gt;
  
      &lt;div id="ConversionSection"&gt;
  
          &lt;form class="form-horizontal" method="post" id= "CurrencyConversion" action="/Currency/Index"&gt;
              @Html.ValidationSummary(true, "", new { @class = "text-danger" })
               &lt;div class="form-group"&gt;
                  &lt;label class="col-sm-4 control-label"&gt;
                      @Html.LabelFor(m =&gt; m.CurrencyToConvert, "Enter Currency")
                  &lt;/label&gt;
                  &lt;div class="col-sm-4"&gt;
                      @Html.EditorFor(m =&gt; m.CurrencyToConvert, new { @class = " form-control" })
                      @*@Html.ValidationMessageFor(m =&gt; m.CurrencyToConvert)*@
                      @Html.ValidationMessageFor(m =&gt; m.CurrencyToConvert, "", new { @class = "text-danger" })
  
  
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label class="col-sm-4 control-label"&gt;
                      @Html.LabelFor(model =&gt; model.fromCurrency.Name, "From Currency")
                  &lt;/label&gt;
                  &lt;div class="col-sm-4"&gt;
                      @Html.DropDownListFor(m =&gt; m.fromCurrency.Name, ViewBag.FromCurrencies as SelectList, "--select--", new { @class = " form-control" })
                      @Html.ValidationMessageFor(model =&gt; model.fromCurrency.Name)
  
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label class="col-sm-4 control-label"&gt;
                      @Html.LabelFor(model =&gt; model.toCurrency.Name, "To Currency")
                  &lt;/label&gt;
                  &lt;div class="col-sm-4"&gt;
                      @Html.DropDownListFor(m =&gt; m.toCurrency.Name, ViewBag.ToCurrencies as SelectList, "--select--", new { @class = "form-control" })
                      @*@Html.ValidationMessageFor(model =&gt; model.toCurrency.Name)*@
  
                      @Html.ValidationSummary(false, "", new { @class = "text-danger" })
  
  
                  &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;div class="form-group"&gt;
                       &lt;label class="col-sm-4 control-label"&gt;
                           @Html.LabelFor(l =&gt; l.ConvertedCurrency, "Value")
                       &lt;/label&gt;
                       &lt;div class="col-sm-4"&gt;
                           @Html.Editor("TheResult", new { @class = " form-control" })
                       &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;div class="form-group"&gt;
                  &lt;div class="col-sm-offset-2 col-sm-4"&gt;
                      &lt;button type="submit" class="btn btn-success"&gt;Submit&lt;/button&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
          &lt;/form&gt;
  
  
      &lt;/div&gt;
  </code></pre>
  
  <p>Currencies.cs</p>
  
  <pre><code>    public class Currencies
      {
          [Required]
          [DataType(DataType.Currency)]
          [DisplayFormat(ConvertEmptyStringToNull = false)]
          public decimal CurrencyToConvert { get; set; }
  
  
          public Currency fromCurrency { get; set; }
  
          public Currency toCurrency { get; set; }
  
          public double ConvertedCurrency { get; set; }
  
      }
  </code></pre>