Try this
public ActionResult Index()
{
connection connect = new connection();
string query = "SELECT Event_Name FROM tbl_Event WHERE Event_ID=2";
return View(connect.SelectRecord(query));
}
internal DataTable SelectRecord(string query)
{
try
{
OpenConnection();
cmd = new SqlCommand(query, conn);
adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
return dt;
}
catch (Exception ex)
{
throw ex;
}
finally
{
cmd = null;
CloseConnection();
}
}
Here is view
View: (strongly typed as System.Data.DataTable)
<table border="1">
<thead>
<tr>
<%foreach (System.Data.DataColumn col in Model.Columns) { %>
<th><%=col.Event_Name%></th>
<%} %>
</tr>
</thead>
<tbody>
<% foreach(System.Data.DataRow row in Model.Rows) { %>
<tr>
<% foreach (var cell in row.ItemArray) {%>
<td><%=cell.ToString() %></td>
<%} %>
</tr>
<%} %>
</tbody>
Check this link : http://weblogs.asp.net/gunnarpeipman/archive/2011/11/19/asp-net-mvc-simple-view-to-display-contents-of-datatable.aspx