Click here to Skip to main content
14,035,479 members
Rate this:
 
Please Sign up or sign in to vote.
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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
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
}
   

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


Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.190424.1 | Last Updated 15 Apr 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100