This resource will be reviewed shortly.
If you think this resource contain inappropriate content, please report to webmaster.
1) Define your viewBag in controller:
// GET: Product/Create
public IActionResult Create()
ViewBag.Categorynames = _context.Category.ToList();
//This is my viewbag
assume that my _context.Category is having CategoryId and CategoryName as key values meaning my database is having a table name as Category with two columns as CategoryId and CategoryName.
2) In your corresponding View you can define dropdownlist as below:
Above code will generate a dropdown list as below:
When you select CategoryName corresponding CategoryId value will be saved in database.
Please post your comments....