I am trying to return a list from MVC controller
. Value is returned easily when I am returning a hard code value. But when I am returning a list, it gives me an error. Here is my code ,
Ajax call,
function MyFunction() {
alert($('#DDlSurvey').val());
$.ajax({
url: "@Url.Action("Index", "ConductSurvey")",
data: { prefix: $('#DDlSurvey').val() },
type: "POST",
dataType: "json",
success: function (data) {
// loadData(data);
alert("Success");
// alert(data)
},
error: function (data){
alert("Failed! Please try again.");
}
});
//$('#YourLabelId').val('ReplaceWithThisValue');
}
and my method is,
[HttpPost]
public JsonResult Index(int prefix)
{
List<SelectList> Questions = new List<SelectList>();
List<Question> QuestionList = new List<Question>();
List<string> ll = new List<string>();
Question nn = new Question();
SurveyAppEntities ObjectSur = new SurveyAppEntities();
QuestionList = (from q in ObjectSur.Questions
join b in ObjectSur.SurveyQuestions on q.ID equals b.QuestionID
where b.SurveyID.Equals(prefix)
select q).ToList();
//return Json("OK");
return new JsonResult {Data=QuestionList, JsonRequestBehavior=JsonRequestBehavior.AllowGet};
}
When I return OK
i get it but when i try to return QuestionList It is not returning data and display Failed
I am also using one link for help in which every thing is as it is link is,
http://www.dotnetawesome.com/2014/05/how-to-retrieve-database-data-show-using-jquery-mvc-asp.html
Hopes for your suggestion