Greetings to all I am new to MVC and I have a problem to show the following model, the table OutMaterial stores the permissions on some kind of material that goes out, the table OutlineMaterial stores specifically the materials that are going to leave with respect to the associated permission of the table OutputMaterial .
I did a model class where I add the two tables
public class SalidaMaterial_LineaSalidaMaterial{
//obtiene las tablas automaticamenete
public SalidaMaterial salidaMaterial { get; set; }
public LineaSalidaMaterial lineaSalidaMaterial { get; set; }
}
In the Details.cshtml section, I'll call that model to show it in the view
@model _VigilanciaIMO.Models.SalidaMaterial_LineaSalidaMaterial
What I have a problem with is the following, I found an example on which I relied but this example only gets ONE SINGLE record and what interests me is to show ALL that belong to the table OutputMaterial .
For that I have the following class SalMat_LinSalMat_Show.cs with the following method
public class SalMat_LinSalMat_Mostrar {
private VigilanciaEntities db = new VigilanciaEntities();
public SalidaMaterial mostrarInformacion(int id){
try{
var lista =
(
from s in db.SALIDAMATERIAL
join l in db.LINEASALIDAMATERIAL
on s.IdSalidaMaterial equals l.IdSalidaMaterialF
where s.IdSalidaMaterial == id
select s
).ToList();
return lista.First();
/* NECESITO MOSTRAR TODOS LOS REGISTROS PERTENECIENTES*/
} catch (Exception e){
Console.WriteLine(e.StackTrace);
return null;
}
}
}
And in the controller in the Details part I do the following but to show only one record.
// GET: AutorizarSalidaMaterial/Details/5
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
SalidaMaterial_LineaSalidaMaterial modelo = new SalidaMaterial_LineaSalidaMaterial();
//el valor 19 es un valor fijo para pruebas
modelo.salidaMaterial = new SalMat_LinSalMat_Mostrar().mostrarInformacion(19);
modelo.lineaSalidaMaterial = modelo.salidaMaterial.LINEASALIDAMATERIAL.First();
//hacer que muestre mas de uno
//buscar el contrario de FirstOrDefault()
return View(modelo);
}
Could you help me please to resolve this detail?