title: Dropdown Data Binding Problem in ASP.NET Core 6 MVC
body: <p>I am using <code>SelectListItem</code> in the controller for binding my dropdown data. All the dropdown options are showing perfectly in the dropdown list, but when I try to save, the problem occurs. It's not adding the dropdown options data rather than its adding dropdown data's id.</p>
  <p>All the related models, controller and views are shown here:</p>
  <p><code>BuyerSelectList</code> model class:</p>
  <pre><code>public class BuyerSelectList
  {
      [Key]
      public int Id { get; set; }
      [DisplayName(&quot;BUYER&quot;)]
      public string Buyer { get; set; }
  }
  </code></pre>
  <p><code>ItemSelectList</code> model class:</p>
  <pre><code>public class ItemSelectList
  {
      [Key]
      public int Id { get; set; }
      [DisplayName(&quot;ITEM&quot;)]
      public string Item { get; set; }
  }
  </code></pre>
  <p><code>BTBNewLien2</code> model class:</p>
  <pre><code>public class BTBNewLien2
  {
      public int Id { get; set; }
      [Required]
      [DisplayName(&quot;Buyer&quot;)]
      public int BuyerSelectListId { get; set; }
      [ForeignKey(&quot;BuyerSelectListId&quot;)]
      [ValidateNever]
      public BuyerSelectList BuyerSelectList { get; set; }
  
      [Required]
      [DisplayName(&quot;Item&quot;)]
      public int ItemSelectListId { get; set; }
      [ForeignKey(&quot;ItemSelectListId&quot;)]
      [ValidateNever]
      public ItemSelectList ItemSelectList { get; set; }
  }
  </code></pre>
  <p><code>BTBNewLien2</code> controller (here I added all the data binding functionalities for my dropdown):</p>
  <pre><code>namespace CommercialCalculatorWeb.Areas.Admin.Controllers
  {
      public class BTBNewLien2Controller : Controller
      {
          private readonly IUnitOfWork _unitOfWork;
  
          public BTBNewLien2Controller(IUnitOfWork unitOfWork)
          {
              _unitOfWork = unitOfWork;
          }
  
          public IActionResult Index()
          {
              IEnumerable&lt;BTBNewLien2&gt; objBTBNewLienList = _unitOfWork.BTBNewLien2.GetAll();
              return View(objBTBNewLienList);
          }
  
          public IActionResult Create()
          {
              BTBNewLien2 btbNewLien2 = new();
  
              IEnumerable&lt;SelectListItem&gt; BuyerSelectList = _unitOfWork.Buyer.GetAll().Select(
                  c =&gt; new SelectListItem
                  {
                      Text = c.Buyer,
                      Value = c.Id.ToString()
                  });
  
              IEnumerable&lt;SelectListItem&gt; ItemSelectList = _unitOfWork.Item.GetAll().Select(
                  c =&gt; new SelectListItem
                  {
                      Text = c.Item,
                      Value = c.Id.ToString()
                  });
  
              ViewBag.BuyerSelectList  = BuyerSelectList;
              ViewBag.ItemSelectList = ItemSelectList;
  
              return View(btbNewLien2);
          }
  
          [HttpPost]
          [ValidateAntiForgeryToken]
          public IActionResult Create(BTBNewLien2 obj)
          {
              if (ModelState.IsValid)
              {
                  _unitOfWork.BTBNewLien2.Add(obj);
                  _unitOfWork.Save();
                  TempData[&quot;success&quot;] = &quot;Row Created Successfully!&quot;;
                  return RedirectToAction(&quot;Index&quot;);
              }
  
              return View(obj);
          }
      }
  }
  </code></pre>
  <p><code>BTBNewLien2</code> create view:</p>
  <pre><code>@model CommercialCalculator.Models.BTBNewLien2
  
  @{
      ViewData[&quot;Title&quot;] = &quot;Create&quot;;
  }
  
  &lt;h1&gt;Create&lt;/h1&gt;
  
  &lt;h4&gt;BTBNewLien2&lt;/h4&gt;
  &lt;hr /&gt;
  &lt;div class=&quot;row ml-6&quot;&gt;
      &lt;div class=&quot;col-md-4&quot;&gt;
          &lt;form asp-action=&quot;Create&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;label asp-for=&quot;BuyerSelectListId&quot; class=&quot;control-label&quot;&gt;Buyer&lt;/label&gt;
                  &lt;select asp-for=&quot;BuyerSelectListId&quot; asp-items=&quot;ViewBag.BuyerSelectList&quot;  class=&quot;form-control&quot;&gt;
                      &lt;option disabled selected&gt;--Select Buyer--&lt;/option&gt;
                  &lt;/select&gt;
              &lt;/div&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;label asp-for=&quot;ItemSelectListId&quot; class=&quot;control-label&quot;&gt;Item&lt;/label&gt;
                  &lt;select asp-for=&quot;ItemSelectListId&quot; asp-items=&quot;ViewBag.ItemSelectList&quot;  class=&quot;form-control&quot;&gt;
                      &lt;option disabled selected&gt;--Select Item--&lt;/option&gt;
                  &lt;/select&gt;
              &lt;/div&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;input type=&quot;submit&quot; value=&quot;Create&quot; class=&quot;btn btn-primary&quot; /&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p><code>BTBNewLien2</code> index view:</p>
  <pre><code>@model IEnumerable&lt;CommercialCalculator.Models.BTBNewLien2&gt;
  @{
      ViewData[&quot;Title&quot;] = &quot;Index&quot;;
  }
  &lt;table class=&quot;table table-bordered table-hover table-sm align-middle m-0&quot; id=&quot;header&quot;&gt;
                          &lt;tr class=&quot;m-0&quot; style=&quot;text-align:center;background-color: #17A2B8&quot;&gt;
                              &lt;th width=&quot;20%&quot;&gt;
                                  @Html.DisplayNameFor(model =&gt; model.BuyerSelectList)
                              &lt;/th&gt;
                              &lt;th&gt;
                                  @Html.DisplayNameFor(model =&gt; model.ItemSelectList)
                              &lt;/th&gt;
                          &lt;/tr&gt;
                          @foreach (var BTBNewLien2 in Model)
                          {
                              &lt;tr class=&quot;m-0&quot;&gt;
                                  &lt;td&gt;
                                      @Html.DisplayFor(modelItem =&gt; BTBNewLien2.BuyerSelectList)
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      @Html.DisplayFor(modelItem =&gt; BTBNewLien2.ItemSelectList)
                                  &lt;/td&gt;
                                  
                              &lt;/tr&gt;
                          }
                      &lt;/table&gt;
  </code></pre>