I using ASP.NET MVC 5 to make a web app, and in my view to list movies and their genres I get this error:
DataTables warning: table id=movies - Requested unknown parameter 'genre.name' for row 0, column 1. For more information about this error, please see http://datatables.net/tn/4
My script in my view:
var table = $("#movies").DataTable({
ajax: {
url: "/api/movies",
dataSrc: ""
},
columns: [
{
data: "name",
render: function(data, type, movie) {
return "<a href='/movies/edit/" + movie.id + "'>" + movie.name + "</a>";
}
},
{
data: "genre.name"
},
{
data: "id",
render: function(data) {
return "<button class='btn-link js-delete' data-movie-id=" + data + ">Delete</button>";
}
}
]
I believe that the genre.namecode is the issue. The genre model simply has two fields and takes it's info from the database. Thank you for the help.
Here is the get method in my api/movies controller:
public IEnumerable<MovieDto> GetMovies()
{
return _context.Movies
.Include(m => m.GenreSet)
.ToList()
.Select(Mapper.Map<Movie, MovieDto>);
}
The MovieDto class has a member field GenreSetDto which has been mapped from my GenreSet class.
Edit: Here is the data I am getting:
[
{
"id": 1,
"name": "Hangover",
"genreId": 0,
"genre": null,
"dateAdded": "2009-04-03T00:00:00",
"releaseDate": "2009-02-03T00:00:00",
"numberInStock": 5
}
]
I see now, that the issue is the genreId is zero which is null because I don't have a genre corresponding to that in the database. The genreId shouldn't be zero though, it should be 2 as I assigned it in the movie database.
nameandgenre.namein your data response?namehas no issue rendering when I load the page though, onlygenre.name./api/movies???genre.namebug. That's probably what CMedina means; you're getting this error because there isn't agenre.nameobject in the JSON data./api/moviesis the web api controller. @Chris H. When I use postman to view my JSON data I just get Unexpected '<' as the result. Is there another way to view my JSON data?