1

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.

7
  • You have name and genre.name in your data response? Commented Jul 7, 2016 at 17:01
  • I'm not sure what that means, I'm sorry. name has no issue rendering when I load the page though, only genre.name. Commented Jul 7, 2016 at 17:05
  • What is return /api/movies??? Commented Jul 7, 2016 at 17:08
  • @ecain You should post your JSON data that is being sent from the server to the client, as that will probably be the source of your genre.name bug. That's probably what CMedina means; you're getting this error because there isn't a genre.name object in the JSON data. Commented Jul 7, 2016 at 17:20
  • @CMedina /api/movies is 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? Commented Jul 7, 2016 at 18:32

2 Answers 2

2

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?

Sign up to request clarification or add additional context in comments.

2 Comments

The genre property should be included though shouldn't it? The movie model has the genre field. How do I check if the generated sql includes foreign table?
I think this article can help you, please take a look msdn.microsoft.com/en-ca/data/jj574232.aspx
-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; }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.