Click here to Skip to main content
15,847,653 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to pass valued from my database to a shared view but I keep getting this error (Please note I am very new to MVC, so I dont understand the error I get) -

 The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery`1[civtbg.Models.tbl_Player_Details]', but this dictionary requires a model item of type 'civtbg.Models.civtbgdbEntities'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery`1[civtbg.Models.tbl_Player_Details]', but this dictionary requires a model item of type 'civtbg.Models.civtbgdbEntities'.

As mentioned I am knew to this, so not sure if there is a place where I can read into this or there might be an "easy" solution for this ?

Thanks for all your help

What I have tried:

I have tried these on the controllers index (so I commented after they gave me the same error as before) -

public ActionResult Index()

     civtbgdbEntities db  = new civtbgdbEntities();
     List<tbl_Player_Details> model = db.tbl_Player_Details.ToList();

 //var PlayerDetails = from s in context.tbl_Player_Details
 //                    select new Models.tbl_Player_Details
 //                    {
 //                        Player_DetailsID = s.Player_DetailsID
 //                    };

 //var PlayerDetails = context.tbl_Player_Details.SingleOrDefault(i => i.Player_ID == 1);

 //var PlayerDetails = from s in context.tbl_Player_Details
 //                        where s.Player_ID == 1
 //                        select s;

     return View(model);

I passed the PlayerDetails when I tested those in the View

In my partial view, I tried these

model List<civtbg.Models.tbl_Player_Details>

In my Shared view I used one of these at the top at a time -

@model List<civtbg.Models.tbl_Player_Details>
    @model IEnumerable<civtbg.Models.tbl_Player_Details>
        @model civtbg.Models.tbl_Player_Details

In the layout I use this -
@Html.Action("Testing", "Home")
, where Testing is calling the my Shared View

In my Shared View I am not trying to display data from the database, only added one of the @model at the top

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900