I have a database with some info, and I need to display the number of rows to webpage. I tried getting the number according to How to retrieve the count of the number of rows in asp.net mvc from sql database? : code in Model:
public int getNumber()
{
using(var con = new SqlConnection("ConnectionString")
{
con.Open();
string query = "SELECT COUNT(*) FROM AspNetUsers"; // table name - AspNetUsers
using (var cmd = new SqlCommand(query, con))
{
return (int)cmd.ExecuteScalar();
}
}
}
How do I display the number to the view? Creating object of the model class doesn't seem to work, since it need Ilogger. I now wonder whether I should put this code in a controller.
