Desidero visualizzare i dati nella visualizzazione griglia utilizzando 3 tabelle nel database SQL.Mostra dati dal database SQL in Gridview
un primo momento ho creato Modello
public class common
{
public Artist Artist { get; set; }
public Album Album { get; set; }
public Genre Genre { get; set; }
}
allora questo è il controller
public ActionResult Show1()
{
var query = from a in DB.Album
join b in DB.Artists
on a.ArtistId equals b.ArtistId
join c in DB.Genre
on a.GenreId equals c.GenreId
where (b.ArtistId == 2)
select new common { Album = a, Artist = b, Genre = c };
return View(query.ToList());
}
}
Dopo di che questo è il mio Vedi
@model IEnumerable<test1.Models.common>
@{
ViewBag.Title = "Show1";
}
<h2>Show1</h2>
<div>
@{
var grid = new WebGrid(Model, defaultSort:"Name");
}
@grid.GetHtml()
</div>
Ma non mostra alcun dato? Come posso farlo?
penso che vi siete persi la domanda ... AKA parte WebGrid – Seabizkit