Cannot implicity List into IEnumerable

user3210023

My ViewModel

public class ViewModelCT
{
    public IEnumerable<SelectListItem> Tests { get; set; }
    public IEnumerable<string> SelectedTests { get; set; }
    public Course course { get; set; }   
}

Controller

public ActionResult Details(int id)
{

    Course course = functionality.toCourse(functionality.GetCourseById(id));
    List<SelectListItem> lsli = new List<SelectListItem>();

    ViewModelCT vm = new ViewModelCT();
    foreach (SchoolService.Test sTest in functionality.GetTestByCourse(id))
    {
        SelectListItem sli = new SelectListItem()
        {
            Text = sTest.Name,
            Value = sTest.Id.ToString(),
            Selected = false
        };
        lsli.Add(sli);
       // vm.Tests.(functionality.toTest(sTest));
    }

    **vm.Tests = lsli;**
    vm.course = functionality.toCourse(functionality.GetCourseById(id));
    return View(vm);    
}

And i get error:

Error 1 Cannot implicitly convert type System.Collections.Generic.List<System.Web.Mvc.SelectListItem> to System.Collections.Generic.IEnumerable<System.Web.WebPages.Html.SelectListItem>. An explicit conversion exists (are you missing a cast?)

I don't know why it is not working.

Charles Mager

As the error implies, System.Web.WebPages.Html.SelectListItem and System.Web.Mvc.SelectListItem are not the same thing. ViewModelCT and your controller are referencing different SelectListItem classes.

Check your using statements in each file. I suspect one has using System.Web.Mvc and the other has using System.Web.WebPages.Html.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Cannot implicity convert type string to List use JavascriptSerializer

From Dev

return different type than generic defined one Error: "Cannot implicity convert type List<A> to List<tableType>"

From Dev

Cannot implicity convert type 'double' to 'string'

From Dev

Cannot implicity convert type "void" to "x"

From Dev

Cannot implicity convert type 'int' to 'ushort' : already explicity cast

From Dev

LINQ - Cannot implicity convert type, An explicit conversion exsist

From Dev

Cannot implicity convert type void to string c#

From Dev

Cannot implicity convert type 'object ' to system.collection.arraylist

From Dev

IEnumerable<IGrouping> to IEnumerable<List>

From Dev

Cannot implicit convert type List to IEnumerable while grouping with Linq

From Dev

Cannot implicitly convert type System.Collections.Generic.List<IEnumerable> to <IEnumerable

From Dev

How To convert Model object list To Data object list in c# implicity

From Dev

Generics - Cannot implicity convert when T constrained to be interface but fine when T an abstract class

From Dev

Cannot implicity convert type System.Linq.Expression<System.Func<Object, bool>> to bool

From Dev

Cannot implicity convert type string to System.Func<string,int,string,string>

From Dev

cannot convert from IEnumerable<T> to IEnumerable<T>

From Dev

how to add object directly to nested ienumerable collection object group by Error- Cannot convert List to Collection

From Dev

Cannot implicitly convert type 'IEnumerable<ob>' to 'Generic.List<cdsworkflows>' nested objects

From Dev

List not converting to IEnumerable

From Dev

How to empty IEnumerable list?

From Dev

Convert List to IEnumerable<SelectListItem>

From Dev

Convert dictionary with List to IEnumerable

From Dev

Inserting a list in an IEnumerable of objects

From Dev

Replacing IEnumerable with List

From Dev

Cannot return type IQueryable or IEnumerable

From Dev

Cannot implicitly convert type 'System.Collections.Generic.List<String>' to 'System.Collections.Generic.IEnumerable<turon.Model.Products_Products>

From Java

Practical difference between List and IEnumerable

From Dev

List<int> assignable from IEnumerable?

From Dev

List<T> vs IEnumerable<T>

Related Related

  1. 1

    Cannot implicity convert type string to List use JavascriptSerializer

  2. 2

    return different type than generic defined one Error: "Cannot implicity convert type List<A> to List<tableType>"

  3. 3

    Cannot implicity convert type 'double' to 'string'

  4. 4

    Cannot implicity convert type "void" to "x"

  5. 5

    Cannot implicity convert type 'int' to 'ushort' : already explicity cast

  6. 6

    LINQ - Cannot implicity convert type, An explicit conversion exsist

  7. 7

    Cannot implicity convert type void to string c#

  8. 8

    Cannot implicity convert type 'object ' to system.collection.arraylist

  9. 9

    IEnumerable<IGrouping> to IEnumerable<List>

  10. 10

    Cannot implicit convert type List to IEnumerable while grouping with Linq

  11. 11

    Cannot implicitly convert type System.Collections.Generic.List<IEnumerable> to <IEnumerable

  12. 12

    How To convert Model object list To Data object list in c# implicity

  13. 13

    Generics - Cannot implicity convert when T constrained to be interface but fine when T an abstract class

  14. 14

    Cannot implicity convert type System.Linq.Expression<System.Func<Object, bool>> to bool

  15. 15

    Cannot implicity convert type string to System.Func<string,int,string,string>

  16. 16

    cannot convert from IEnumerable<T> to IEnumerable<T>

  17. 17

    how to add object directly to nested ienumerable collection object group by Error- Cannot convert List to Collection

  18. 18

    Cannot implicitly convert type 'IEnumerable<ob>' to 'Generic.List<cdsworkflows>' nested objects

  19. 19

    List not converting to IEnumerable

  20. 20

    How to empty IEnumerable list?

  21. 21

    Convert List to IEnumerable<SelectListItem>

  22. 22

    Convert dictionary with List to IEnumerable

  23. 23

    Inserting a list in an IEnumerable of objects

  24. 24

    Replacing IEnumerable with List

  25. 25

    Cannot return type IQueryable or IEnumerable

  26. 26

    Cannot implicitly convert type 'System.Collections.Generic.List<String>' to 'System.Collections.Generic.IEnumerable<turon.Model.Products_Products>

  27. 27

    Practical difference between List and IEnumerable

  28. 28

    List<int> assignable from IEnumerable?

  29. 29

    List<T> vs IEnumerable<T>

HotTag

Archive