I'm trying to pass a custom shaped class to a view, but I'm having a little trouble.
This is the error I'm getting.
Cannot implicitly convert type 'System.Linq.IQueryable' to 'Project.Models.TaskTimeLine'. An explicit conversion exists (are you missing a cast?)
This is the first time I've added a list to a class, and trying to pass one inside the other as it were.
Here is the class definition
public class TaskTimeLine
{
public Task task { get; set; } // to hold a single object
public List<DateTime> scheduledDateTime { get; set; } // to hold a collection of date times..
}
The controller action is along the lines of this.
[Authorize]
public ActionResult Details2(int id)
{
TaskTimeLine task = new TaskTimeLine(); //create new instance of TaskTimeLine
task = (IQueryable<TaskTimeLine>)taskRepository.GetTaskAndTimeLine(id);
if (task == null)
return View("NotFound");
else
return View("Details", task);
}
All quite normal up until now, so I'm guessing maybe something is going wrong here.
public IQueryable<TaskTimeLine> GetTaskAndTimeLine(int taskId)
{
TaskTimeLine taskTimeLine = new TaskTimeLine(); // create new main object
taskTimeLine.scheduledDateTime = new List<DateTime>(); instanciate list object inside
taskTimeLine.task = db.Tasks.SingleOrDefault(d => d.id == taskId); read the record to fill the single task object
/// Lots of logic is performed here to add loads of date records to the list object.
/// If I add a break point and check the list I can see that all the date items have gone fine into the collection
return (IQueryable<TaskTimeLine>)taskTimeLine;
}
The only reason I have so many odd casts in places is because it seemed that these helped the program compile. It currently doesn't compile, but I did get to, but when running the actual request it fails, with the same error message.
Can anyone help, also perhaps with add a more useful title for future people who are stuck with this kind of thing.