0

After executing the application I get the "The model item passed into the dictionary is of type 'ClubStarterKit.Web.ViewData.Forum.NewMessageListViewData', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[ClubStarterKit.Web.ViewData.Forum.NewMessageListViewData]'.

In view I have the codes below

    <%if ( User.Identity.IsAuthenticated) { %>

        <div class="fullwidth" id="message-add-block">
          <%using (Ajax.AsyncForm(Website.Shared.Views.DisplayTemplates.NewForumMessageList, new AsyncFormOptions(AsyncFormType.TargetUpdate, FormMethod.Post, "newMessages", targetUpdate: "messages", elementBlockId: "message-add-block", postRequestFunction: "afterMessageUpdate")))
          {%>
                <h3>Add New Message Final Test</h3>
                <br />
                <%: Html.Wysiwyg("message") %>
                <br />
               <%-- <input type="hidden" value="<%: Model.ThreadSlug %>" name="thread" />--%>
                <input type="hidden" value="-1" name="messageId" />
                <input type="submit" value="Add Message4 final" />
          <%}%>




          <br />
          <a id="newmessage" href="#">New message4 final</a>
        </div>

          <%}%>

in the controller the code is

 public virtual ActionResult Index()
    {
        ViewData.Title("New Message");
        return View(Views.List, new ClubStarterKit.Web.Infrastructure.Forum.NewMessageListAction().Execute());
    }

and in screenshot below it is :

Error

The model item passed into the dictionary is of type 'Myapplication.Web.ViewData.application.NewMessageListViewData', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable

Please advise which area of code is the issue

user998007
  • 131
  • 3
  • 15

1 Answers1

2

You are passing the View a single NewMessageListViewData, but it has been strongly typed to accept only objects implementing IEnumerable<T> where T is NewMessageListViewData. For example, a List<NewMessageListViewData> would work.

As mentioned in the comments, I would start by looking at the return type of ClubStarterKit.Web.Infrastructure.Forum.NewMessageListAction.Execute(), or, if you only intend to display a single instance of NewMessageListViewData in this View, you need to set the model in the View to reflect that.

Dan Nixon
  • 101
  • 1
  • 7