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>
toSystem.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.
As the error implies,
System.Web.WebPages.Html.SelectListItem
andSystem.Web.Mvc.SelectListItem
are not the same thing.ViewModelCT
and your controller are referencing differentSelectListItem
classes.Check your using statements in each file. I suspect one has
using System.Web.Mvc
and the other hasusing System.Web.WebPages.Html
.