i am sending ajax call to controller where list of objects is filled from database and returned to view. list is stored in TempData and json as well in controller.i have received it in my view but don't know how to display it through TempData or Json result ? how to fix it ?
controller code :
[HttpGet]
public ActionResult Read_Quran()
{
List<thing> Records = new List< thing> ();
//database stuff goes here
//...
int count = 0;
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
thing obj = new thing();
obj.surah = Convert.ToInt32( reader["Surah_ID"] );
obj.verse = (string) reader["Ayat_Description"];
Records.Add(obj);
count++;
if (count == 6236)
break;
}
TempData["message"] = Records;
connection.Close();
return Json(new {key= Records }, JsonRequestBehavior.AllowGet);
}
view code :
$.ajax({
url: "Read_Quran?ayah="+ayah,
type: 'GET',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
async: false,
data: '',
success: function (result) {
alert("success.!");
var mera_obj = result.key;
alert("data is : ???");
},
error: function (xhr, ajaxOptions, thrownError) {
alert("Error : " + xhr.responseText);
},
});
alert in success is hit ...