I am trying to send two values from view to controller using ajax call one is the array of string like [‘1′,’2′,’3’] and the other is string value. Here is my ajax call code
$('#multiEditBtn').click(function () {
var selectedPointCategory = '@ViewBag.pointCategory';
var selectedIds = ['1','2','3'];
$.ajax({
url: "@Url.Action("UpdateMultiPointInfo", "URL")",
type: 'POST',
contentType: "application/json; charset=utf-8",
traditional: true,
data: JSON.stringify({ 'pointIds': selectedIds, 'pointCategory': selectedPointCategory }),
});
});
The action method code is given below
[HttpPost]
public ActionResult UpdateMultiPointInfo(List<string> pointIds, string pointCategory)
{
}
The action method is hitting successfully but getting the null values in both parameters.
3
Answers
Okay so regarding your case, you need to change your
AJAX
call to:Since you are sending an array of
int
in your case, you need to handle them in yourController
action method like this:One of the possible solutions using the
JsonConvert.DeserializeObject<T>()
convertor (requires to install theNewtonsoft.Json
NuGet package).And on the server side:
Have you tried not using
JSON.stringify
?Maybe try this: