Cannot implicitly convert type

namespace LibraryManagement.Models

{

    public partial class UserList

    {

        public long Id { get; set; }

        public string UserName { get; set; }

        public string Address { get; set; }

        public int? Quantity { get; set; }

        public int Price { get; set; }

        public bool? Available { get; set; }

    }

}

UserListService.cs

public IEnumerable<UserList> GetUserLists()

        {

            try

            {

                return _context.UserLists.ToList();

            }

            catch

            {

                throw;

            }

        }

UserList.razor

@code

    {         public IEnumerable<UserList> LibraryBooks { get; set; }

              protected override void OnInitialized()

                {

                    LibraryBooks = UserListService.GetUserLists();

                }

    }


 'System.Collections.Generic.IEnumerable<LibraryManagement.Models.UserList>' to 'System.Collections.Generic.IEnumerable<LibraryManagement.Pages.UserList>'. An explicit conversion exists (are you missing a cast?) LibraryManagement D:\Library\LibraryManagement\Pages\UserList.razor



5 Replies

VN Vignesh Natarajan Syncfusion Team January 27, 2022 05:28 AM UTC

Hi Antony,  
 
Thanks for contacting Syncfusion support.  
 
Query: “Cannot implicitly convert type” 
 
From the below error, we found that you have defined the UserList class in both Models as well as Pages. Hence the reported (typecast) issue has occurred. Kindly remove UserList class from one reference to resolve the reported issue.  
 
'System.Collections.Generic.IEnumerable<LibraryManagement.Models.UserList>' to 'System.Collections.Generic.IEnumerable<LibraryManagement.Pages.UserList>'. An explicit conversion exists (are you missing a cast?) LibraryManagement D:\Library\LibraryManagement\Pages\UserList.razor 
 
If above solution does not resolve your query, kindly share more details about the issue you are facing.  
 
Regards, 
Vignesh Natarajan. 



AN Antony January 30, 2022 12:30 PM UTC

if i remove from this razor page , how to call this model call?




VN Vignesh Natarajan Syncfusion Team January 31, 2022 04:50 AM UTC

Hi Antony,  
 
Query: “if i remove from this razor page , how to call this model call? 
 
Consider the WeatherForecast class defined in Data folder of the Blazor Server application. We can access that model class using its class namespace. Refer the below code example.  
 
Razor page 
 
@using BlazorGrid_Server.Data 
@code{ 
    public WeatherForecast Forecast = new WeatherForecast(); 
} 
  
Data folder - > weatherforecast.cs 
 
 
namespace BlazorGrid_Server.Data 
{ 
    public class WeatherForecast 
    { 
        public DateTime Date { get; set; } 
        public int TemperatureC { get; set; } 
        public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 
        public string? Summary { get; set; } 
    } 
} 
 
Similar way we can access the model class in razor page. Kindly get back to us if you have further queries or if we misunderstood your query.  
 
Regards, 
Vignesh Natarajan 




AN Antony January 31, 2022 09:56 AM UTC

Thanks Vignesh.

I fixed the issue. Thank you for your valuable support.

Many Thanks,




VN Vignesh Natarajan Syncfusion Team February 1, 2022 05:58 AM UTC

Hi Antony,  

Thanks for the update.  

We are glad to hear that you have resolved your query using our solution.  

Please get back to us if you have further queries.  

Regards, 
Vignesh Natarajan 


Loader.
Up arrow icon