Below is a method I have:
[HttpPost]
public ActionResult GetData()
{
var data= (dynamic)null;
using (DBContext context = new DBContext())
{
data= context.MyObject.Where(i=> i.TypeId == 1).OrderBy(k => k.Name).Select(w => new
{
description = w.Description
}).ToList();
}
return Json(data, JsonRequestBehavior.AllowGet);
}
I am unsure if I am correctly converting the data into a JSON object as needed for use in JavaScript.
After researching extensively, I came across an example similar to the one below. Maybe I should implement something along these lines, but I'm not exactly sure how:
var keyValues = new Dictionary<string, string>
{
{ "emailSend", textBox1.Text },
{ "toEmail", textBox2.Text }
};
JavaScriptSerializer js = new JavaScriptSerializer();
string json = js.Serialize(keyValues);
MessageBox.Show(json);