Error with model MVC Model.get null

0

I'm developing a web page with MVC, and although the connection to the database works for me (for the login) with the LINQ class and SQL Server, I do not know if the model does not load the data or the list is not adding the data of the BD ... In the Models folder I have the classes queries, login and the one that has the fields of the table in the database

namespace WebApplication3.Models{ 
public class tblProyecto
{
    public int idpro { get; set; }
    public int ideest { get; set; } 
    public int idase { get; set; }
    public string NomProy { get; set; }
    public string EstadoProy { get; set; }
}}

// In the class consultations I have the following code

namespace WebApplication3.Models{
public class Consultas
{
    private SqlConnection Conexion;

      //EL METODO PARA CONECTARME A LA BD YA ESTÄ DEFINIDO 
    public List<tblProyecto> ListarTodos()
    {
        ConectarDB();
        List<tblProyecto> Proyecto = new List<tblProyecto>();
        SqlCommand Consulta = new SqlCommand("SELECT * FROM TBLPROYECTO", Conexion);
        Conexion.Open();
        SqlDataReader dataReader = Consulta.ExecuteReader();
        while (dataReader.Read())
        {
            tblProyecto InfoProyecto = new tblProyecto
            {
                idpro = int.Parse(dataReader["IDPROYECTO"].ToString()),
                NomProy = dataReader["STR_NOMBRE_PROYECTO"].ToString(),
                ideest = int.Parse(dataReader["ID_ESTUDIANTE_U"].ToString()),
                idase = int.Parse(dataReader["ID_ASESOR"].ToString()),
                EstadoProy = dataReader["ESTADO_PROYECTO"].ToString()
            };
            Proyecto.Add(InfoProyecto);
        }
        Conexion.Close();
        return Proyecto;
    }

}

// IN THE CONTROLLER I HAVE THE SGTE METODO

public ActionResult UsuarioEst()
    {

        Consultas C = new Consultas();
        return View(C.ListarTodos());
    }

// AND IN THE SIGHT THE SGTE

@model IEnumerable <WebApplication3.Models.tblProyecto>

<h2>Usuario</h2>


<table style="width:100%">
<tr>
    <th>Nombre Proyecto</th>
    <th>Nombre Estudiante</th>
    <th>Nombre Asesor</th>
    <th>Estado Proyecto</th>
</tr>

@foreach (var estudiante in Model)
{
    <tr>
        <th>@estudiante.idpro</th>
        <th>@estudiante.NomProy</th>
        <th>@estudiante.ideest</th>
        <th>@estudiante.idase</th>
        <th>@estudiante.EstadoProy</th>
    </tr>

</table>

// Now the error is that I see a System.NullReferenceException and it tells me that the model is null, the model that is in the foreach of the view ... I have made many changes and nothing has worked for me. I hope you can help me. Thank you very much.

    
asked by José Ibargüen Posada 06.12.2018 в 05:21
source

0 answers