MVC C# Controller Method to return Tables

Posted by Rob Tiu on Stack Overflow See other posts from Stack Overflow or by Rob Tiu
Published on 2012-10-28T16:56:51Z Indexed on 2012/10/28 17:00 UTC
Read the original article Hit count: 210

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

© Stack Overflow or respective owner

Related posts about c#

Related posts about asp.net-mvc-3