I am attempting to generate customized lists in my cshtml file through an ajax request.
.ajax({
type: "GET",
cache: false,
url: "@Url.Action("getValidationLists")",
contentType: "application/json",
dataType: "json",
success: function (result) {
var list = result.list;
$.each(list, function (index, value) {
alert(value);
});
}
});
In order to achieve this, the Controller fetches the data, organizes it into a List, and sends it back to my cshtml file in json format. Here is the controller method responsible:
[HttpGet]
[Authorize]
public JsonResult getValidationLists()
{
List<List<String>> validList = new List<List<String>>();
List<UIReferenceData> results = AddErrorsToModelState <List<UIReferenceData>>(_StaticDataServiceAgent.GetAllAssetTypes());
for (int i = 0; i < results.Count; i++)
{
List<String> resultList = new List<String>();
string id = results[i].ID.ToString();
string name = results[i].Name;
resultList.Add(id);
resultList.Add(name);
validList.Add(resultList);
}
return Json(new
{
validList = validList
}, JsonRequestBehavior.AllowGet);
}
Despite trying multiple variations, the script never reaches the point of executing the alert(value); line. What could I be overlooking?