I've just started learning ASP MVC. So far, i was using web forms, and i've got a lot of classes from web form web application. With GridViews that works fine, now i'am looking a solution how to present data from database in MVC. I've got a lot of classes like this one:
public class zmienneWczytywanieTresci
{
public int druzynaID { get; set; }
public string Druzyna { get; set; }
public string LiczbaMeczy { get; set; }
public string LiczbaGoliStrzelonych { get; set; }
public string LiczbaGoliStraconych { get; set; }
public string Zwyciestwa { get; set; }
public string Remisy { get; set; }
public string Porazki { get; set; }
public string Punkty { get; set; }
}
public static List<zmienneWczytywanieTresci> wczytajTabele(string query, string grupa)
{
List<zmienneWczytywanieTresci> wczytajTabele = new List<zmienneWczytywanieTresci>();
string CS = ConfigurationManager.ConnectionStrings["ligiConnection"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
con.Open();
SqlCommand com = new SqlCommand(query, con);
com.Parameters.AddWithValue("@Grupa", grupa);
SqlDataReader rdr = com.ExecuteReader();
while (rdr.Read())
{
zmienneWczytywanieTresci infoTabela = new zmienneWczytywanieTresci();
int druzynaID = Convert.ToInt32(rdr["Druzyna"]);
infoTabela.Druzyna = wczytajNazweKlubu(druzynaID);
infoTabela.LiczbaMeczy = rdr["LiczbaMeczy"].ToString();
infoTabela.LiczbaGoliStrzelonych = rdr["LiczbaGoliStrzelonych"].ToString();
infoTabela.LiczbaGoliStraconych = rdr["LiczbaGoliStraconych"].ToString();
infoTabela.Zwyciestwa = rdr["Zwyciestwa"].ToString();
infoTabela.Remisy = rdr["Remisy"].ToString();
infoTabela.Porazki = rdr["Porazki"].ToString();
infoTabela.Punkty = rdr["Punkty"].ToString();
wczytajTabele.Add(infoTabela);
}
return wczytajTabele;
}
}
Is there option to present data from that list using foraech loop ?. I'am creaing a ViewBag with that lis.. and i dont know what to do now, I'can't find any solution. Many thanks for any advise !