Click here to Skip to main content
15,921,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

Here is my Model defined in MVC5 application:


What I have tried:

This is my action
public ActionResult CQuestions()
        {
            using (UserAccountContext userAccount = new UserAccountContext())
            {
                return View(userAccount.InterviewQuestions.ToList<interviewquestions>());
            }
        }

This is my view
@model List<alohomora.models.interviewquestions>
@{
    ViewBag.Title = "CQuestions";
}




This is the exception
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[AlohoMora.Models.InterviewQuestions]', but this dictionary requires a model item of type 'AlohoMora.Models.User'.
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.Collections.Generic.List`1[AlohoMora.Models.InterviewQuestions]', but this dictionary requires a model item of type 'AlohoMora.Models.User'.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:
Posted
Updated 15-Apr-19 1:13am
v2
Comments
F-ES Sitecore 15-Apr-19 10:22am    
The code you have posted can't generate that error. The error might be coming from a partial view you are using in the view?

1 solution

What I would do is to start by expanding out the controller to do your troubleshooting; and then insert a breakpoint just before returning the value so that you can see exactly what is being returned.
C#
public ActionResult CQuestions() {
  List questions = new List<interviewquestions>();

  using (UserAccountContext userAccount = new UserAccountContext()) {
    questions = userAccount.InterviewQuestions.ToList<interviewquestions>();
  }
  return View(questions);  // insert breakpoint at start of this line
}
 
Share this answer
 

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