I am currently working on a ASP.NET MVC project for which I created a controller with an Action method which will return a JsonResult. The action basically goes into a DB and based on a table name passed to the action should do a dynamic linq query and return the rows for the desired table.
My Action method looks like this:
public async Task<JsonResult> FieldValues(string table)
{
using (DbEntities ctx = new DbEntities())
{
Type type = System.Reflection.Assembly.GetExecutingAssembly().GetType("MyWebApp.Models." + table);
var query = ctx.Set(type).SqlQuery(string.Format("SELECT * FROM {0}", table));
var data = await query.ToListAsync();
return Json(data, JsonRequestBehavior.AllowGet);
}
}
This action is invoked using jquery ($.get(...)) from the view... I tried to debug the action, the table is passed properly, the query seems ok, but the return statement is never reached!
It's the first time I am using an async action method and also the first time I'm using "dynamic linq".
Any help on what I might have done wrong is appreciated!
Thank you!