I am trying to post a full form and a separate list of strings to my controller. The form binds to the model but the list of strings doesn't bind to the list of strings in the controller and shows as a single string in a list.
var List = "one,two,three";
var dataToPost = $('#Form').serialize() + "&Words=" + JSON.stringify(List);
$.ajax({
type: "POST",
url: '/Home/Open/',
data: dataToPost,
dataType: "json",
success: function () {
alert('ok');
},
error: function () {
alert('error');
}
});
Here is my MVC controller action:
[HttpPost]
public IActionResult Open(DataModel Model, List<string> Words)
{
return View(Model);
}
Listarray to a URL-encoded string before appending it to thedataToPost. Maybe something like in the answers here stackoverflow.com/questions/26717228/… will help you