I have this method on one of my controllers for getting a dropdownlist:
public JsonResult GetPeople(int roleId)
{
return Json(_uow.GetPeople(roleId).Select(e => new SelectListItem { Text = e.Name, Value = e.Id.ToString() }).ToList());
}
so basically it gets a whole bunch of people within a particular role and returns a selectlistitem list in json.
I'm unsure whether it should be decorated with [HttpGet] or [HttpPost]. I'm thinking it should be a get because that's essentially what your doing, getting info from the server even though you do post an id.
So it has no decoration so by default is a GET.
This is how I call it in jquery:
$.get('/People/GetPeople', { roleId: $('#roleddl').val() }, function (data) {
$(data).each(function () {
$("<option value=" + this.Value + ">" + this.Text + "</option>").appendTo(peopleddl);
});
});
So here I'm using the $.get. It didn't work. So I was thinking it's returning json so I tried $.getJSON which didn't work. So then I tried $.post and it worked as:
$.post('/People/GetPeople', { roleId: $('#roleddl').val() }, function (data) {
$(data).each(function () {
$("<option value=" + this.Value + ">" + this.Text + "</option>").appendTo(peopleddl);
});
});
So I'm wondering why is a jquery post call working when the method it is calling is no a POST.
Also even though this works what combination should I have. ie. What should the method be decorated with and what should I use to call it?