Hello, I'm all working on a project in MVC 5 with the Data Entity migrations, generate a table but now to that same project I want to make a query of another existing table, a SELECT
and send the records as a table to a view, but not modify anything of the structure of the table, which already has records. Below I leave my code.
Model:
using System;
using System.Data.Entity;
namespace MvcMovie.Models
{
public class Municipios // clase nombrada igual que la tabla ya existente la cual no fue generada con migraciones
{
public int ID { get; set; } // nombrados igual que las columnas
public string Municipio { get; set; }
public string Estado { get; set; }
}
public class MunicipiosDBContext : DbContext
{
public DbSet<Municipios> Municipios { get; set; }
}
}
Controller:
private MunicipiosDBContext db = new FormularioDBContext();
// GET: /Movies/
public ActionResult Index()
{
return View(db.Municipios.ToList());
}
View:
@model IEnumerable<Proyecto.Models.Municipios>// aquí tengo problema cuando quiero agregar dos tablas al mismo tiempo,una generada por migraciones que es un archivo, y su clase, y el otro que les muestro aquí, no se la sintaxis para agregar los dos modelos que son archivos separados en models. EN esta view ya muestor unos inputs con valores de la tabla generada por las migraciones, pero tambien quiero mostrar los registros de una tabla generada en sql en esta misma view
@{
ViewBag.Title = "Details";
}
@foreach (var item in Model) {
<tr>
<th>Municipio
</th>
<th>Estado
</th>
</tr>
<td>
<td>id=item.Municipio</td>
<td> id=item.Estado
</td>
</tr>
}