Hello Stack colleagues, I currently want to run some data through a cycle foreach
but I have a problem always throws me the following error
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: The foreach block is missing a closing "}" character Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
part of my controller:
// GET: CalificarColaboradors
public ActionResult Index(string id)
{
var calificado = (from p in db.CalificarColaboradors
where p.codigo_colaborador == id
select p.codigo_objetivos).ToList();
var codigo = calificado[0];
ViewBag.listobjetivos = (from p in db.Objectives
where p.Codigo_Objetivos == codigo
select p).ToList();
ViewBag.calificacion = (from p in db.CalificarColaboradors
where p.codigo_objetivos == codigo
select p).ToList();
ViewBag.fecha_actual = DateTime.Now.ToString("yyyy-MM-dd");
ViewBag.Data_Collaborator = (from p in db.Collaborators
where p.codigo == id
select p).ToList();
return View();
}
Part of my view:
<tbody>
<tr style="background-color: rgba(112, 183, 50, 0.35);">
<th>Objetivos</th>
<th>Peso: 20%</th>
<th>Descripción</th>
<th>Calificación</th>
<th>Observación</th>
</tr>
@foreach (var i in ViewBag.listobjetivos)
{
<tr>
<td>@i.Nombre_Objetivo</td>
<td>@i.Peso_Objetivo%</td>
<td>@i.Descripcion_Objetivo</td>
}
@foreach (var o in ViewBag.calificacion)
{
<td>@o.calificacion</td>
<td>@o.observacion</td>
</tr>
}
</tbody>
and an image of what is seen by the error:
the error is solved when in the first foreach
@foreach (var i in ViewBag.listobjetivos)
it closes but it is not the idea, because I need both foreach to be a line.
Any questions or questions remain attentive.
UPDATE
They tell me that I can do a join in the query to nest them or put them together, but I honestly do not know how the procedure is done. My tables are these
I tried to do it in the following way and I got 16 results, and at this moment they would be 4.
ViewBag.test = (from p in db.Objectives
join pm in db.CalificarColaboradors on p.Codigo_Objetivos
equals pm.codigo_objetivos
where pm.codigo_objetivos == codigo
select new { Post = p, Meta = pm }).ToList();