title: How to automatically add a name from selected id in View page from controller ASP.NET MVC
body: <p>I want to get a name from selected id in my view page</p>
  <p>First Model</p>
  <pre><code>public class Transaction
  {
      [Key]
      public int Id { get; set; }
      [Required]
      public int supplier_id { get; set; }
      [Required]
      public string supplier_name { get; set; }
  }
  </code></pre>
  <hr />
  <p>Second Model</p>
  <pre><code>public class Supplier
  {
      [Key]
      public int supplier_id { get; set; }
      [Required]
      public string supplier_name { get; set; }
  }
  </code></pre>
  <hr />
  <p>View Model</p>
  <pre><code>public class EvaluateSheet
  {
      public IEnumerable&lt;Supplier&gt; Suppliers{ get; set; }
      public IEnumerable&lt;Transaction&gt; Transactions { get; set; }
      public Transaction Transaction { get; set; }
  }
  </code></pre>
  <hr />
  <p>Controller</p>
  <pre><code>public IActionResult Sheet11()
      
      {
          var sup = _db.Supplier.ToList();
          ViewBag.Sup = new SelectList(sup, &quot;supplier_id&quot;, &quot;supplier_name&quot;);
          return View();
      }
  [HttpPost]
  [ValidateAntiForgeryToken]
  public IActionResult Sheet11(EvaluateSheet objc)
      {
             Transaction Model = objc.Transaction;
             Transaction transaction = new Transaction();
             transaction.Id = Model.Id;
             transaction.supplier_id = Model.supplier_id;
             transaction.supplier_name = Model.supplier_name;
             _db.Transaction.Add(Model);
             Model.supplier_name = Model.Supplier.supplier_name.Where(Model.Supplier.supplier_id == Model.supplier_id);
             _db.SaveChanges();
             return RedirectToAction(&quot;Index&quot;);
      }
  </code></pre>
  <hr />
  <p>View Page</p>
  <pre><code>@model EvaluateSheet 
  &lt;form method=&quot;post&quot;&gt;
  &lt;select asp-for=&quot;@Model.Transaction.supplier_id&quot; asp-items=&quot;@ViewBag.Sup&quot; value=&quot;@ViewBag.Sup&quot; class=&quot;form-control&quot;&gt;
                      &lt;option selected disabled&gt;--choose supplier--&lt;/option&gt;
  &lt;/select&gt;
  &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;Add Transaction&lt;/button&gt;
  </code></pre>
  <hr />
  <p>I want to automatically insert supplier_name field after I selected supplier_id in my View page into the database.
  I have tried this in my controller but it doesn't work</p>
  <pre><code>Model.supplier_name = Model.Supplier.supplier_name.Where(Model.Supplier.supplier_id == Model.supplier_id);
  </code></pre>