Trouble with MVC 4 DropDownListFor

Amit Jog

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.

enter image description here

Instead of names of vendors.

Please suggest whats wrong with my code.

Eric_Lin

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

DropDownListFor ASP MVC4

From Dev

Set @Html.Dropdownlistfor to session in MVC 4

From Dev

Selected value for dropdownlistfor in mvc4

From Dev

Set @Html.Dropdownlistfor to session in MVC 4

From Dev

How to populate an dropdownlistfor from database in ASP.NET MVC 4

From Dev

MVC4 DropDownListFor Object reference not set to an instance of an object

From Dev

MVC 4 Changing multiple display fields based on DropDownListFor selection

From Dev

ASP.NET mvc4 DropDownListFor pass back an object

From Dev

How to set Default value in MVC 4 razor DropDownListFor

From Dev

How to extend the DropDownListFor() in MVC

From Dev

MVC Entity Framework DropDownListFor<>

From Dev

How to extend the DropDownListFor() in MVC

From Dev

MVC Entity Framework DropDownListFor<>

From Dev

MVC MultipleModel DropdownlistFor SaveChanges()

From Dev

MVC 5 DropDownListFor Database Linq;

From Dev

DropDownListFor MVC : How to make it work

From Dev

MVC DropDownListFor Bind on Nested Class

From Dev

MVC DropDownListFor how to add RouteLink

From Dev

ArgumentNullException on MVC5 DropdownListFor

From Dev

ASP MVC 4 MySQL, trouble handling transaction error

From Dev

Trouble with Knockout JSON Model parsing MVC 4 Controller

From Dev

Having trouble understanding the purpose of the arguments for Html.DropDownListFor

From Dev

Cascading DropDownListFor ASP.NET MVC

From Dev

Dropdownlistfor MVC ASP.Net VB

From Dev

Getting selected Index from DropDownListFor MVC

From Dev

C# MVC DropDownListFor List of Strings

From Dev

MVC DropDownListFor - Selected Value ViewModel Class

From Dev

Dropdownlistfor MVC 5 in ListView (IEnumerable of Viewmodel)

From Dev

MVC DropDownListFor with ViewBag not passing value to controller

Related Related

  1. 1

    DropDownListFor ASP MVC4

  2. 2

    Set @Html.Dropdownlistfor to session in MVC 4

  3. 3

    Selected value for dropdownlistfor in mvc4

  4. 4

    Set @Html.Dropdownlistfor to session in MVC 4

  5. 5

    How to populate an dropdownlistfor from database in ASP.NET MVC 4

  6. 6

    MVC4 DropDownListFor Object reference not set to an instance of an object

  7. 7

    MVC 4 Changing multiple display fields based on DropDownListFor selection

  8. 8

    ASP.NET mvc4 DropDownListFor pass back an object

  9. 9

    How to set Default value in MVC 4 razor DropDownListFor

  10. 10

    How to extend the DropDownListFor() in MVC

  11. 11

    MVC Entity Framework DropDownListFor<>

  12. 12

    How to extend the DropDownListFor() in MVC

  13. 13

    MVC Entity Framework DropDownListFor<>

  14. 14

    MVC MultipleModel DropdownlistFor SaveChanges()

  15. 15

    MVC 5 DropDownListFor Database Linq;

  16. 16

    DropDownListFor MVC : How to make it work

  17. 17

    MVC DropDownListFor Bind on Nested Class

  18. 18

    MVC DropDownListFor how to add RouteLink

  19. 19

    ArgumentNullException on MVC5 DropdownListFor

  20. 20

    ASP MVC 4 MySQL, trouble handling transaction error

  21. 21

    Trouble with Knockout JSON Model parsing MVC 4 Controller

  22. 22

    Having trouble understanding the purpose of the arguments for Html.DropDownListFor

  23. 23

    Cascading DropDownListFor ASP.NET MVC

  24. 24

    Dropdownlistfor MVC ASP.Net VB

  25. 25

    Getting selected Index from DropDownListFor MVC

  26. 26

    C# MVC DropDownListFor List of Strings

  27. 27

    MVC DropDownListFor - Selected Value ViewModel Class

  28. 28

    Dropdownlistfor MVC 5 in ListView (IEnumerable of Viewmodel)

  29. 29

    MVC DropDownListFor with ViewBag not passing value to controller

HotTag

Archive