Hi. i have first page name"Homepage.cshtml", second page, "UnitDetails.cshtml". My model name is "DetailBundle" and controller is "Home"
my table databases are table "Tester" and "Parameter" where the foreign key is "ParameterID"
in Homepage, i have table which displays all tester name (from db.tester). and if i click the tester name, it will direct to UnitDetails and it will bring the TesterID data. In database, i have specify every tester name with its condition whether good/bad. (note that good/bad is in db.Parameter)
so i want my table to colour according to good:green and Bad:red.
i tried using the query but when i run it state exeption unhandled.
What I have tried:
this is my controller:
public ActionResult Homepage()
{
List<DetailBundle> query = (from i in db.Testers
from a in db.Parameters
.Where(a => a.ParameterID == i.ParameterID)
select new DetailBundle
{
TesterID = i.TesterID,
TesterName = i.TesterName,
Param_desc = a.Param_desc
}).Distinct().OrderBy(i => i.TesterID).ToList();
ViewBag.TesterUnit = query;
return View();
}
this is my Homepage:
@if (Tester.Contains(ViewBag.TesterUnit[i].TesterName))
{
if (ViewBag.TesterUnit[i].Param_desc == "Good")
{
<td class="custom" style="text-align:center; color:red">
@Html.ActionLink((string)ViewBag.TesterUnit[i].TesterName, "UnitDetails", new { id = (object)ViewBag.TesterUnit[i].TesterID }, new { target = "_blank" })
</td>
}
else if (ViewBag.TesterUnit[i].Param_desc == "Bad")
{
<td class="custom" style="text-align:center; color:green">
@Html.ActionLink((string)ViewBag.TesterUnit[i].TesterName, "UnitDetails", new { id = (object)ViewBag.TesterUnit[i].TesterID }, new { target = "_blank" })
</td>
}
else
{
<td class="custom" style="text-align:center; color:white">
@Html.ActionLink((string)ViewBag.TesterUnit[i].TesterName, "UnitDetails", new { id = (object)ViewBag.TesterUnit[i].TesterID }, new { target = "_blank" })
</td>
}
i++;
if (Tester.Contains(ViewBag.TesterUnit[i].TesterName))
{
if (ViewBag.TesterUnit[i].Param_desc == "Good")
{
<td class="custom" style="text-align:center; color:red">
@Html.ActionLink((string)ViewBag.TesterUnit[i].TesterName, "UnitDetails", new { id = (object)ViewBag.TesterUnit[i].TesterID }, new { target = "_blank" })
</td>
}
else if (ViewBag.TesterUnit[i].Param_desc == "Bad")
{
<td class="custom" style="text-align:center; color:green">
@Html.ActionLink((string)ViewBag.TesterUnit[i].TesterName, "UnitDetails", new { id = (object)ViewBag.TesterUnit[i].TesterID }, new { target = "_blank" })
</td>
}
else
{
<td class="custom" style="text-align:center; color:white">
@Html.ActionLink((string)ViewBag.TesterUnit[i].TesterName, "UnitDetails", new { id = (object)ViewBag.TesterUnit[i].TesterID }, new { target = "_blank" })
</td>
}
}
i++;
if (Tester.Contains(ViewBag.TesterUnit[i].TesterName))
{
if (ViewBag.TesterUnit[i].Param_desc == "Good")
{
<td class="custom" style="text-align:center; color:red">
@Html.ActionLink((string)ViewBag.TesterUnit[i].TesterName, "UnitDetails", new { id = (object)ViewBag.TesterUnit[i].TesterID }, new { target = "_blank" })
</td>
}
else if (ViewBag.TesterUnit[i].Param_desc == "Bad")
{
<td class="custom" style="text-align:center; color:green">
@Html.ActionLink((string)ViewBag.TesterUnit[i].TesterName, "UnitDetails", new { id = (object)ViewBag.TesterUnit[i].TesterID }, new { target = "_blank" })
</td>
}
else
{
<td class="custom" style="text-align:center; color:white">
@Html.ActionLink((string)ViewBag.TesterUnit[i].TesterName, "UnitDetails", new { id = (object)ViewBag.TesterUnit[i].TesterID }, new { target = "_blank" })
</td>
}
}
}