Let's say I have two tables. Inventory and Supplier. Inventory has three fields : name, inventory_no and supplier_no and Supplier has two fields : name, supplier_no
In my View for Inventory is it possible to add a cell with a @Html.DropDownListFor() populated from a separate supplies model?
I can't figure out how to accomplish it using the Controller/View so I was thinking about using AJAX
Example:
Name | Inv_no | Suppliers
------- | ------ | ------------------------------
Pen | 101 | DDL populated of all suppliers
Pencil | 102 | DDL populated of all suppliers
Erase | 103 | DDL populated of all suppliers
VIEW:
<table>
<tr>
<th>Name</th>
<th>Inventory_No</th>
<th>Suppliers</th>
<tr>
@foreach(var item in Model)
{
<td>@Html.DisplayFor(modemItem => item.name)</td>
<td>@Html.DisplayFor(modemItem => item.inventory_no)</td>
<td><!-- @Html.DropDownListFor() ? --></td>
}
</table>
Controller:
public virtual JsonResult getListOfSuppliers(int? supplier_no)
{
using (db)
{
var vendors = db.vendors.Select(c => new
{
Value = c.supplier_no,
Text = c.name
});
return Json(vendors, JsonRequestBehavior.AllowGet);
}
}