I am having trouble with displaying Dropdownlist
in MVC 4 application. It looks straightforward, However something is still missing which is not getting hold of.
ViewModel
public class vendorModel
{
public int vendorID { get; set; }
public int vendorTypeID { get; set; }
public string vendorName { get; set; }
public IEnumerable<vendorTypeModel> vendorTypes { get; set; }
}
public class vendorTypeModel
{
public int vendorTypeID { get; set; }
public string vendorTypeName { get; set; }
}
Controller
[HttpGet]
public ActionResult Vendor() {
vendorModel oVendor = new vendorModel();
oVendor.vendorTypes = blVendor.getAllVendorTypes();
return View(oVendor);
}
getAllVendorTypes
Method This is where I am fetching records from database and building and returning a List<vendorTypeModel>
object. and Finally on View am using following code.
@Html.DropDownListFor(m => m.vendorTypeID, new SelectList(Model.vendorTypes,"vendorTypeID","vendorTypeName"))
What am I doing wrong? I am getting following results on screen.
Instead of names of vendors.
Please suggest whats wrong with my code.
I suspect that oVendor.vendorTypes = blVendor.getAllVendorTypes();
may return a wrong list back. Set a breakpoint and check the oVendor.vendorTypes
please.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments