MVC C# Controller Method to return Tables
- by Rob Tiu
I'm a real beginner with MVC and my issue is this, I have a mdf database with multiple tables and I want to have a method return "ANY" table from the database and pass it to a aspx view.
Examples of other tables in the database: Articles, Products, Supplies
Here is an example of my code to view an Article Table from the database:
//USING LINQ-SQL CONTEXT DATABASE
public ActionResult ArticlePage()
{
tinypeas_db_contextDataContext context = HttpContext.Application["context"] as tinypeas_db_contextDataContext;
try
{
return View(context.Articles);
}
catch
{
return Json(false, JsonRequestBehavior.AllowGet);
}
}
How would I modify this method to dynamically pass any table to the view? Or should I be using something else other than Linq-to-SQL