Hi,
I've been experimenting with ASP.NET MVC and following this tutorial to create the basic task list application. I've gotten it running fine, everything is working although the video is in VB and I had some trouble getting it "converted" to C# but muddled through thanks to the codesample.
Now, to further my knowledge I've decided to make a small modification to the system. I want to change the Index page so as to display "My Tasks" in red if all tasks are complete, and "My Tasks" in green if there are any incomplete tasks.
I've added the following function to HomeController.cs:
public bool Uncomplete()
{
bool AnyLeft = false;
var tasks = from t in db.Tasks orderby t.EntryDate descending select t;
foreach (Task match in tasks)
{
if (match.IsCompleted == false)
{
AnyLeft = true;
}
}
return AnyLeft;
}
I then modified the Index() ActionResult to look like this:
public ActionResult Index()
{
bool AnyLeft = Uncomplete();
var tasks = from t in db.Tasks orderby t.EntryDate descending select t;
return View(tasks.ToList());
}
With my final intent to use the following code in Index.aspx:
<% if (AnyLeft == false)
{ %>
<h1 class="green">My Tasks</h1>
<% }
else
{ %>
<h1 class="red">My Tasks</h1>
<% } %>
However, I can't figure out how to make Index.aspx "aware" of AnyLeft having a value of true or false. I tried
return View(tasks.ToList(), AnyLeft);
But that throws errors that I can't quite decipher. I have a feeling I'm going about things "the wrong way" but I can't figure it out.
Cheers, Rob