Hello experts
I have a list from movie.js file, I want to send my list to HomeController in Passthings function. But when I use a breakpoint on the PassThings function, I notice that the list(i mean,I do not receive this list in my function that I send from the javascript file ) in PassThings function is empty.
This is the code of my movie.js file:
function fun1() {
$(document).ready(function () {
var things = [
{ id: 1, color: 'yellow' },
{ id: 2, color: 'blue' },
{ id: 3, color: 'red' }
];
var thing = {
ThingList : things
}
$.ajax({
dataType: 'json',
type: 'POST',
url: '/Home/PassThings',
data: thing,
success: function () {
$('#result').html('"PassThings()" successfully called.');
},
failure: function (response) {
$('#result').html(response);
}
});
});
}
SaveBtn.addEventListener('click', fun1);
and here is my Home/Passthings Action:
public void PassThings(List<Thing> things)
{
var t = things;
}
and here is my model :
public class Thing
{
public int Id { get; set; }
public string Color { get; set; }
}
and in the my Index.cshtml i use this to call my movie.js file :
<pre>
<div class="col-6 col-md-3">
<button type="submit" id="SaveBtn" class="btn btn-primary form-control">Save</button>
</div>
<script src="~/js/movie.js"></script>
What I have tried:
i tried with using [httpPost]
and i tried with IActionResult too :
[HttpPost]
public IActionResult PassThings ([FromBody]IEnumerable<Thing> things)
{
return Ok();
}