Reputation: 1302
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.name
code 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.
Upvotes: 1
Views: 907
Reputation: 1
Add GenreDto to MovieDto class, and it should work.
public class MovieDto {
public int Id { get; set; }
[Required]
[StringLength(255)]
public string MovieName { get; set; }
public DateTime? ReleaseDate { get; set; }
//public DateTime? DateAdded { get; set; }
public byte NumberInStock { get; set; }
public int MovieGenreId { get; set; }
public GenreDto Genre { get; set; }
}
Upvotes: -1
Reputation: 321
Seems like the "Genre" property is not included in your api call, if you are using Entity Framework check if the generated sql included foreign tables?
Upvotes: 2