DROPDOWN FOR RAZOR FORM:MVC DOTNET

Note:Initially Create two tables and inherit a content from one table to other.

Controller Code:

public ActionResult FSRCreate()
{
List<tblEquipmentMake> EquipmentmakeList = db.tblEquipmentMakes.ToList();
ViewBag.EquipmentmakeList = new SelectList(EquipmentmakeList, "Id", "EquipmentMake");
return View();
}

Consider “EquipmentmakeList” is a field in Table1 and it inherits the value from the table named “EquipmentMake”.

View Code:

<td>
Equipment Make
<br />
@if (ViewBag.EquipmentmakeList != null)
{
@Html.DropDownListFor(model => model.Eqp_Make, ViewBag.EquipmentmakeList as SelectList, "--Select--", new { style = "width:130px;" })
}
</td>

Leave a Reply

Your email address will not be published. Required fields are marked *