Istudent Rana

Istudent Rana

  • 1.4k
  • 342
  • 84k

How to pass string array to asp.net mvc action method or Api

Feb 18 2018 5:46 PM
I am trying to pass strings array to my mvc action but I am getting Null value.  
 
This is my javascript/Jquery 
 
var array = ["Good Morning", "Good Afternoon", "Good Evening"]
var postData= { imageList: array };
$('button').on('click', function () {
$.ajax({
url: "/Home/Greetings",
type: 'POST',
data: postData,
dataType: "json",
traditional: true,
success: function (data) {
array = [];
},
error: function (xhr, status, err) {
}
});
});
 
My Code in Asp.net MVC is 
[HttpPost]
public string Greetings(List postData)
{
string result = "";
foreach(var item in postData)
{
result += item + " ";
}
return result;
}

Answers (12)