There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'Credit'

Ungaro

I am really struggling with Html.DropdownList. Identical code worked under VS2012 but fails with the subject error under VS2013. Any help would be deeply appreciated.

Controller (selectedCredit is int):

var creditQuery = from d in db.CreditStatus
                    orderby d.CreditId
                    select new { d.CreditId, d.Reason };
ViewBag.Credit = new SelectList(creditQuery.ToList(), "CreditId", "Reason", selectedCredit);

View:

@Html.DropDownList("Credit", null, new { @class = "form-control" })

If the second parm of Html.DropdownList is not null, it will ignore selectedCredit and no item will be selected.

List list shows correctly but fails on Post with the subject error. HELP!

Morten Anderson

Once you do a POST to server the viewbag needs to be repopulated

Insert this in your post action

var creditQuery = from d in db.CreditStatus
                orderby d.CreditId
                select new { d.CreditId, d.Reason };
ViewBag.Credit = new SelectList(creditQuery.ToList(), "CreditId", "Reason", selectedCredit);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key '...'

From Dev

There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key "key"

From Dev

There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'Register.CountryId'

From Dev

There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key country

From Dev

There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'CategoryID

From Dev

There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'CicekListesi'

From Dev

There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'PestType'

From Dev

There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'CategoryID

From Dev

There is no ViewData item of type IEnumerable<SelectListItem>' that has the key 'DCResults'

From Dev

There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key "Projects"

From Dev

"There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'Skip'

From Dev

There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'SelectedCategoriesIds'

From Dev

There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'CicekListesi'

From Dev

There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'ddlcataglist'

From Java

The ViewData item that has the key 'XXX' is of type 'System.Int32' but must be of type 'IEnumerable<SelectListItem>'

From Dev

The ViewData item that has the key 'CategoryId' is of type 'System.Int32' but must be of type 'IEnumerable<SelectListItem>'

From Dev

The ViewData item that has the key 'JobTitleID' is of type 'System.Int32' but must be of type 'IEnumerable<SelectListItem>'?

From Dev

The ViewData item that has the key 'CountryId' is of type 'System.Int32' but must be of type 'IEnumerable<SelectListItem>'

From Dev

Scaffolded model/view: The ViewData item that has the key 'COLUMN' is of type 'System.String' but must be of type 'IEnumerable<SelectListItem>'

From Dev

c# MVC Dropdownlist - There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key ' '

From Dev

There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key "Auteur_du_Livre"

From Dev

There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'Country.Name'. even when I don't use ViewData

From Dev

Why is there an error, "There is no ViewData item of type 'IEnumerable<SelectListItem>'..."

From Dev

Exception "There is no ViewData item of type 'IEnumerable<SelectListItem>" MVC

From Dev

ASP.NET MVC - Dropdown - There is no ViewData item of type 'IEnumerable<SelectListItem>'

From Dev

ASP.NET MVC - Dropdown - There is no ViewData item of type 'IEnumerable<SelectListItem>'

From Dev

"There is no ViewData item of type 'IEnumerable<SelectListItem>'" error with custom model and list

From Dev

DropDownListFor no ViewData item of type IEnumerable

From Dev

How to add item to IEnumerable SelectListItem

Related Related

  1. 1

    There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key '...'

  2. 2

    There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key "key"

  3. 3

    There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'Register.CountryId'

  4. 4

    There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key country

  5. 5

    There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'CategoryID

  6. 6

    There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'CicekListesi'

  7. 7

    There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'PestType'

  8. 8

    There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'CategoryID

  9. 9

    There is no ViewData item of type IEnumerable<SelectListItem>' that has the key 'DCResults'

  10. 10

    There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key "Projects"

  11. 11

    "There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'Skip'

  12. 12

    There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'SelectedCategoriesIds'

  13. 13

    There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'CicekListesi'

  14. 14

    There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'ddlcataglist'

  15. 15

    The ViewData item that has the key 'XXX' is of type 'System.Int32' but must be of type 'IEnumerable<SelectListItem>'

  16. 16

    The ViewData item that has the key 'CategoryId' is of type 'System.Int32' but must be of type 'IEnumerable<SelectListItem>'

  17. 17

    The ViewData item that has the key 'JobTitleID' is of type 'System.Int32' but must be of type 'IEnumerable<SelectListItem>'?

  18. 18

    The ViewData item that has the key 'CountryId' is of type 'System.Int32' but must be of type 'IEnumerable<SelectListItem>'

  19. 19

    Scaffolded model/view: The ViewData item that has the key 'COLUMN' is of type 'System.String' but must be of type 'IEnumerable<SelectListItem>'

  20. 20

    c# MVC Dropdownlist - There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key ' '

  21. 21

    There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key "Auteur_du_Livre"

  22. 22

    There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'Country.Name'. even when I don't use ViewData

  23. 23

    Why is there an error, "There is no ViewData item of type 'IEnumerable<SelectListItem>'..."

  24. 24

    Exception "There is no ViewData item of type 'IEnumerable<SelectListItem>" MVC

  25. 25

    ASP.NET MVC - Dropdown - There is no ViewData item of type 'IEnumerable<SelectListItem>'

  26. 26

    ASP.NET MVC - Dropdown - There is no ViewData item of type 'IEnumerable<SelectListItem>'

  27. 27

    "There is no ViewData item of type 'IEnumerable<SelectListItem>'" error with custom model and list

  28. 28

    DropDownListFor no ViewData item of type IEnumerable

  29. 29

    How to add item to IEnumerable SelectListItem

HotTag

Archive