I cannot seem to figure out why my $.get call returns one single object with a string containing my elements, when my controller returns a list of objects.
Controller:
public JsonResult GetInitialTags(int id)
{
Model = new UnitDetailsModel(UnitClient.GetUnit(id));
foreach (var tag in Model.ViewUnitContract.Tags)
{
Model.TagsSelected.Add(tag);
}
var result = Model.TagsSelected.Select(a => new
{
id = a.Id,
text = a.Name
});
return Json(result, JsonRequestBehavior.AllowGet);
}
This returns an array of two objects ([0], [1]). But, when I do my ajax call from view, like this:
var data = $.get('@Url.Action("GetInitialTags", "UnitDetails", new { id = Model.ViewUnitContract.Id })');
.. it returns one single object with a property responseText that contains my elements like this:
responseText: "[{"id":27,"text":"Norway"},{"id":28,"text":"Sweden"}]"
Any help would be appreciated! :)