Member 14248437 Ответов: 1

Элемент модели, передаваемый в словарь, имеет тип 'system.collections.generic.list`1[alohomora.models.interviewquestions]', но для этого словаря требуется элемент модели типа 'alohomora.models.user'


Hi all,

Here is my Model defined in MVC5 application:


Что я уже пробовал:

Это мое действие
public ActionResult CQuestions()
        {
            using (UserAccountContext userAccount = new UserAccountContext())
            {
                return View(userAccount.InterviewQuestions.ToList<interviewquestions>());
            }
        }

Это моя точка зрения
@model List<alohomora.models.interviewquestions>
@{
    ViewBag.Title = "CQuestions";
}




Это исключение
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:

F-ES Sitecore

Код, который вы опубликовали, не может генерировать эту ошибку. Ошибка может быть вызвана частичным представлением, которое вы используете в представлении?

1 Ответов

Рейтинг:
0

MadMyche

Что бы я сделал, так это начал с расширения контроллера для устранения неполадок; а затем вставил точка прерывания непосредственно перед возвращением значения, чтобы вы могли точно видеть, что возвращается.

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
}