I'm running a simple mvc site, by college. I have to make a crud. I created a getall method that lists all existing clients in a list.
How can I step the same for the view? I tried the line below but I can not use ..
@model List<cliente>
Model Client with metadata get all
public List<Cliente> getall()
{
string StringDeConexao = @"CONNECTION";
List<Cliente> clientes = new List<Cliente>(); //instancia lista
using (SqlConnection cn = new SqlConnection(StringDeConexao))
{
{
cn.Open();
SqlCommand cmd = new SqlCommand("Select * from cliente", cn);
var dr = cmd.ExecuteReader();
while (dr.Read())
{
Cliente cliente = new Cliente();
cliente.ID = (int)dr["ID"];
cliente.Nome = (string)dr["Nome"];
cliente.Email = (string)dr["Email"];
cliente.Tel = (string)dr["Tel"];
cliente.Cidade = (string)dr["Cidade"];
cliente.Documento = (string)dr["Documento"];
cliente.Data = (DateTime)dr["Data"];
clientes.Add(cliente);
}
}
catch (SqlException e)
{
MessageBox.Show(e.Message);
}
finally
{
cn.Close();
}
return clientes;
}
}
Customer Controller
public ActionResult List(Cliente cliente)
{
cliente.getall();
return View(cliente);
}
View Customer
div class="table">
<table>
<thead>
<tr>
<td>ID</td>
<td>Nome</td>
<td>E-mail</td>
<td>Tel</td>
<td>Cidade</td>
<td>Documento</td>
<td>Data</td>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div>
How to display list in view without entity framework?