you need to understand types. a variable has a defined type. at compile and runtime, during assignment, a check is done that the types match. ignoring the assignment override that allows int to assigned to doubles, when
a = b;
b must implicitly be cast-able as the type of a at compile time.
interface are special in that they define an abstract type, that is it defines properties and methods, but no implementation. you can not new an interface (or abstract class).
lets look at some simple interface, class and inheritance examples:
// define some interfaces
public interface ISayHello
{
string SayHello();
}
public interface ISayGoodBye
{
string SayGoodBye();
}
// define simple base classes to implement interfaces
public class Test1Base : ISayHello
{
public string SayHello() => $"{WhoAmI()}> Hello";
public virtual string WhoAmI() => "Test1Base";
}
public class Test2Base : ISayGoodBye
{
public string SayGoodBye() => $"{WhoAmI()}> GoodBye";
public virtual string WhoAmI() => "Test2Base";
}
public class Test3Base : ISayHello, ISayGoodBye
{
public string SayHello() => $"{WhoAmI()}> Hello";
public string SayGoodBye() => $"{WhoAmI()}> GoodBye";
public virtual string WhoAmI() => "Test3Base";
}
// define inheritance
public class Test1 : Test1Base
{
public override string WhoAmI() => "Test1";
}
public class Test2 : Test2Base
{
public override string WhoAmI() => "Test2";
}
public class Test3 : Test2Base
{
public override string WhoAmI() => "Test3";
}
now we can see what can be at construction
var test = new ISayHello(); // error can not new interface
var test = new Test1Base(); // implicit type
Test1Base test = new Test1Base(); // explicit type
Test1Base test = new Test2Base(); // error mismatched types
Test1Base test = new Test3Base(): // error mismatched types
Test1Base test = new Test1(); // downcast Test1 to Test1Base
ISayHello test = new Test1Base(); // explicit implementation of interface
ISayHello test = new Test2Base(); // error no implementation
ISayHello test = new Test3Base(); // explicit implementation of interface
ISayHello test = new Test3(); // explicit implementation of interface via inheritance
so what between defining as interface or class
var test = new Test3(); // implicit type Test3
test.SayHello(); // valid
test.SayGoodBye(); // valid
test.WhoAmI(); // valid
ISayHello test = new Test3();// explicit type of interface
test.SayHello(); // valid
test.SayGoodBye(); // error
test.WhoAmi(); // error
ISayHello test = new Test3();// explicit type of interface
test.SayHello(); // valid
test.SayGoodBye(); // error
test.WhoAmi(); // error
// cast object to valid type
ISayHello test = new Test3(); // explicit type of interface
test.SayHello(); // valid - interface
((ISayGoodBye)test).SayGoodBye(); // valid - cast to intface
((Test3Base)test).SayGoodBye(); // valid - cast base class
((Test3)test).SayGoodBye(); // valid - cast to object actual class
now lets look at your examples:
IList vUE_WRITE_KBASE_SOURCE = new List<IList>();
the variable is declare as type IList. a simple inference that allows collection operations where the items are type object
the constructor is List<IList>. List<> is a generic that implements both IList and IList<>. This constructs a collection of IList types (lists of objects).
so when you add to vUE_WRITE_KBASE_SOURCE, the item must be of type IList, but you can not create a new IList, you must use a class that implements IList.
IList vUE_WRITE_KBASE_SOURCE = new List<IList>();
vUE_WRITE_KBASE_SOURCE.Add(new List<int>()); // add a list of ints downcast to IList
vUE_WRITE_KBASE_SOURCE.Add(new List<string>()); // add a list of strings downcast to IList
your error message is because the model return to the view is of explicit type List<IList>, but the view is expecting IEnumberable<Models.VUE_WRITE_KBASE_SOURCE>, but you are pass collection of a collection of objects.
you did:
IList Result = new List<IList>();
IEnumberable<VUE_WRITE_KBASE_SOURCE> Model = Result;
but Result a list of lists of objects, can not be cast to a Collection of VUE_WRITE_KBASE_SOURCE.
but you really wanted:
IList Result = new List<IList<>();
@Model IEnumberable<IEnumberable<VUE_WRITE_KBASE_SOURCE>>
but this fails because you can not do an implicit of IList to a collection of VUE_WRITE_KBASE_SOURCE.
so you need to define the Model as IList or IList<IList> and use casting to access the items of the inner list, or define
IList<IList<VUE_WRITE_KBASE_SOURCE> Result = new List<IList<VUE_WRITE_KBASE_SOURCE>();
@Model IEnumberable<IEnumberable<VUE_WRITE_KBASE_SOURCE>>
downcasts work.