C
C#

Can't access object attributes using X.PagedList

Can't access object attributes using X.PagedList

MBMurilo Barbosa11/18/2023
I have a search field that returns a list of movies. It works fine if I reference the model as @MovieSearch in the View. But I want to use pagination so it won't break with thousands of results if someone types "a". I'm trying to use X.PagedList, but when I use IPagedList<MovieSearch> as model I can't access the MovieSearchResults[] results property inside MovieSearch in the View, and that contains most of the data I want to retrieve from the search. Basically I can't access anything inside "results" below. public class MovieSearch { public int? page { get; set; } public MovieSearchResult[]? results { get; set; } public int? total_pages { get; set; } public int total_results { get; set; } } public class MovieSearchResult { public string? backdrop_path { get; set; } public string? first_air_date { get; set; } public int[]? genre_ids { get; set; } public int? id { get; set; } public string? title { get; set; } public string[]? origin_country { get; set; } public string? original_language { get; set; } public string? original_title { get; set; } public string? overview { get; set; } public float? popularity { get; set; } public string? poster_path { get; set; } public float? vote_average { get; set; } public int? vote_count { get; set; } } The search results come as objects from a SearchMovies method, I'm not accessing any local DB. This model comes from the API. Any ideas?
SSaber11/18/2023
Sounds to me like your not using the IPagedList correctly. It should probably be IPagedList<MovieSearchResult> as the page list itself will already contain the pagination inormation, so having your own class that has paging info doesn't make sense.
MBMurilo Barbosa11/18/2023
I think you are right. But now I'm getting this error InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'System.Threading.Tasks.Task1[X.PagedList.IPagedList1[Cinemanage.Models.TMDB.MovieSearchResult]]', but this ViewDataDictionary instance requires a model item of type 'X.PagedList.IPagedList`1[Cinemanage.Models.TMDB.MovieSearchResult]'. This is how I'm returning it from the Action: if (!String.IsNullOrEmpty(searchTerm)) { movies = await _tmdbMovieService.SearchMoviesAsync(searchTerm); } var movieResults = movies.results.ToPagedListAsync(pageNumber, pageSize); return View(movieResults); I think it doesn't like the "movieResults = movies.results" But otherwise I can't use the ToPagedListAsync Oh Just needed the await Hehe, all good now. Damn I need some time away. Been grinding Thanks

Looking for more? Join the community!

C
C#

Can't access object attributes using X.PagedList

Join Server
Want results from more Discord servers?
Add your server
Recommended Posts
Tryin to install scriptscs but cinst is not a recognized commandI'm trying to install scriptcs but cinst isn't a recognized command. I have uninstalled and reinstalHow do I utilize Identity Framework and AspNetUser Table?Hello, I am building an MVC app where people will need to sign up. They can then upload stuff to th✅ Is there a way to run a commands method inside of another command? (DSharpPlus)Title explains it. ```c# #region RandomImage [SlashCommand("randomimage", "Visa en rhelpGood evening, I have a monolithic application completed, can someone help me migrate a monolithic apProject structure (MVC API, microservice arch.)https://github.com/classy-giraffe/BookshopHow can I insert my sortedlist into a listbox?I am new to C# and currently using a sortedlist<string, int> in order to store values that I need toHow to map Entity Framework entities containing circular references to DTOs?When querying data with Entity Framework, the result data appears to contain circular references. (✅ Typeorm doesnt get the name from entityI need that typeorm get the ```name: "noInfoMILeadsToDistribute"``` inside Entity, but it wants to gProcessing files as fast as possibleHi everyone! I have a question that I’m sure you can help me with. I’m making a library that needs t✅ [SOLVED] Does the 3rd line of code hold memory as a reference or does it hold the actual value?ayooo, quick question. pretty simple. Book is a custom class just so you know.... ```csharp Book boRequestsHello, i have never done something that i will say before, how can i send a request to an API Url, gWhy is my grid on Line 28 not calling back to my other script called Grid?✅ Visual Studio 2022 Failing to Create C# ProjectWhat's happening here?✅ Help with creating shapes on a windows form appI have created a windows form app to display shapes on a bitmap, my circle function works fine but mNo inbuilt functionsHello, im a year 1 student so my knowledge is not that massive. So i have this task for university wSignalR initial connection takes way too long (logs included in comments)Hey there. So I have two versions of the same application, using essentially the same code. One of ✅ How to make DontDestroyOnLoad work for only single scene?Hello! I have a problem. In my game, when I am on my Main Menu Scene and trying to load Main Game ScUI is lagging while scrolling a listViewHi, I wanted to create an application that retrieves data from the API and displays it. I'm having tHow can i fix this error code?he's giving me an error code for private?Visual Studio 2022 ExtensionI'm working on a visual studio 2022 Extension. But as soon as i import it inside the visual studio 2