I have an MVC Action which accepts a list of values as shown below:
[HttpGet]
public JsonResult Events(string[] vals)
{
var events = _lcmEventsRepository.FindAllByEventTypeId(vals[0]);
return Json(events);
}
How to send some values to this Action from javascript?
I'm using the below code but the value which is received at the server side is not in the right format:
var eventtypes = ['1', '2'];
$.ajax({
url: shouldRepopulateFromAction,
//data: { vals: JSON.stringify(selectedValues) },
data: { vals: JSON.stringify(eventtypes) },
type: 'GET',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert(data);
},
error: function (data) {
alert('error!');
}
});
vals parameter has one member with the value of
["1","2"]
traditional: true,parameter? and don't useJSON.stringify