ASP.NET MVC - Get the data from database and display as sort-able grid:
.cshtml page
@{
var db = Database.Open("tutorial"); // db connection string
var selectQueryString = "SELECT * FROM students ORDER BY id"; // sort by id by default
var data = db.Query(selectQueryString);
var grid = new WebGrid(data);
}
<div id="grid">
@grid.GetHtml()
</div>
Web config database connection string:
<add name="tutorial" connectionString="Data Source=localhost;Initial Catalog=students;Integrated Security=true;" providerName="System.Data.SqlClient"/>
.cshtml page
@{
var db = Database.Open("tutorial"); // db connection string
var selectQueryString = "SELECT * FROM students ORDER BY id"; // sort by id by default
var data = db.Query(selectQueryString);
var grid = new WebGrid(data);
}
<div id="grid">
@grid.GetHtml()
</div>
Web config database connection string:
<add name="tutorial" connectionString="Data Source=localhost;Initial Catalog=students;Integrated Security=true;" providerName="System.Data.SqlClient"/>