The model item passed into the dictionary is of type 'DSDB_V1.Models.DSDB_STORE_TBL', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[DSDB_V1.Models.DSDB_STORE_TBL]'.

AppDev 20 Reputation points
2023-03-21T20:05:04.97+00:00

Hi All I am so confused by this thing. One type of list work... a list with a find or where statement creates an error. No really understanding why. This is the mvc below is the source codes... maybe some one can help.

What it is that I am trying to do. I am simply making a from that allows me to enter a code that will be used to query the database so that I can down load the fille stored in the database.

Seems like the MVC,,, he does not like dealing with the list

THis is the view

User's image

THis is the controller and the function that fails is gate

User's image

The Error Page he makes

User's image

What is odd is if I put this in the controller the view works fine

            DSDBEntities DB_Entities = new DSDBEntities();             return View(DB_Entities.DSDB_STORE_TBL.ToList());

The view has this

@model IEnumerable<DSDB_V1.Models.DSDB_STORE_TBL>

For some reason this works. But I I try to filter the list he says that I can because:

The model item passed into the dictionary is of type 'DSDB_V1.Models.DSDB_STORE_TBL', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[DSDB_V1.Models.DSDB_STORE_TBL]'.

This does not make since to be how one list work and a list that has been filtered will not work, thank makes no sense to me and makes this very confusing.

No some will say its because he is not enumerated... I will have to be honest. I do not know what that really means in computer regards. WHen I research the defeminations it does not make sense what he trying to say.

Why does this not work as a list that can display in the view:

            DSDBEntities DB_Entities = new DSDBEntities();

           return View(DB_Entities.DSDB_STORE_TBL.ToList().Find(d => d.DOC_SOURCE_DISC == "WRITE"));

Why does this work in the view

            DSDBEntities DB_Entities = new DSDBEntities();
            return View(DB_Entities.DSDB_STORE_TBL.ToList());

I need to filter this list from the screen with input via the description filed but I don't to return everything because there will be items from many different sources. Here is the user interface working the wrong way.

User's image

The right way will be the user see this screen first

User's image

They type the code User's image

As see the list from the database. That word WRITE filters the description from the database field.

User's image

Can someone help and tell me why is he so wrong??? Thank you so much in advance.

Sorry it would not let put code for some reason

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,250 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,228 questions
0 comments No comments
{count} votes

Accepted answer
  1. Lan Huang-MSFT 25,471 Reputation points Microsoft Vendor
    2023-03-22T07:05:08.98+00:00

    Hi @AppDev,

    Why does this not work as a list that can display in the view:

    DB_Entities.DSDB_STORE_TBL.ToList().Find(d => d.DOC_SOURCE_DISC == "WRITE")

    The problem is that your query returns IQueryable.

    You need to convert it to List (which is an IEnumerable).

    Why does this work in the view

    That's why DB_Entities.DSDB_STORE_TBL.ToList() works.

    I need to filter this list from the screen with input via the description filed

    You can try the following code:

     DSDBEntities DB_Entities = new DSDBEntities();        
     return View(DB_Entities.DSDB_STORE_TBL.Where(d => d.DOC_SOURCE_DISC == "WRITE").ToList());
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful