Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4559146
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:44:51+00:00 2026-05-21T17:44:51+00:00

I have what appears (to me anyway) to be a strange problem… I created

  • 0

I have what appears (to me anyway) to be a strange problem…

I created a simple editor template for a SelectListItem (SelectListItem.cshtml in the ~/Views/Shared/EditorTemplates folder), for example:

<ul class="select-list-item cell-15 col-3 omega clearfix">
    @Html.EditorFor(c => c.Categories)
</ul>

Where c.Categories is an IEnumerable

This worked fine, but I wanted another template to render the collection with slightly different markup, so I copied and renamed the editor template to, for example, ‘CategoryIcons.cshtm’ and invoked as follows:

<ul class="select-list-item cell-15 col-3 omega clearfix">
    @Html.EditorFor(c => c.Categories, "CategoryIcons")
</ul>

In short, the only difference is I’m specifying a named editor template.

When I open the page, I now get the following error:

The model item passed into the dictionary is of type ‘System.Collections.Generic.List`1[System.Web.Mvc.SelectListItem]’, but this dictionary requires a model item of type ‘System.Web.Mvc.SelectListItem’

The template’s model declaration, in both templates id:

@model System.Web.Mvc.SelectListItem

I don’t understand why the default template works and the named template doesn’t. Any help would be appreciated.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T17:44:52+00:00Added an answer on May 21, 2026 at 5:44 pm

    When you call @Html.EditorFor(c => c.Categories) it is falling back to the default template for IEnumerable. This default template is provided by the MVC framework, and its behaviour is to output Html.EditorFor() for each item in the enumeration. That in turn emits the appropriate editor template for each item in the list individually – in your case they’re all instances of SelectListItem, so in the first case, the SelectListItem template is used for each item.

    In the second case, by explicitly setting your EditorFor to use a particular editor template CategoryIcons, you are telling it to use that editor template for the whole enumeration, instead of allowing the enumerable to be templated by default, in turn using the template for each enumerated item.

    I’m not sure of the best way around this just yet.

    One approach would be to define a CategoryIcons template, whose model is an instance of IEnumerable<CategoryIcon>, which simply foreaches the Model enumeration, and performs Html.EditorFor for each item, with an explicit template reference of CategoryIcon. You then put your per-item editor template in that template (CategoryIcon not CategoryIcons). You would then call this by doing @Html.EditorFor(c => c.Categories, "CategoryIcons").

    I’m going to have a look around to see if there are better ways to get this done, but I hope this might be useful for now. It would be great if templates could be parameterized, so you could write an IEnumerable template that takes as an argument the name of the template to use for each of its items.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found what appears to be a strange bug with sqlite. I have
Update : The problem appears to have been corrupt DLLs somewhere in my PHP
I have a problem that appears and disappears for mysterious reasons. A while back
I have a problem where in some cases (appears to be where property type
Winforms' ListBox appears to have a strange behavior. When I set the SelectionMode to
I have a strange issue that is occurring before my code appears to reach
I have built a simple Android application to solve an annoying problem. Whenever you
I am having a kinda strange problem. Here is the situation. I have a
I have what appears to be a corrupt index? Here is what is happening.
I have encountered what appears to be a bug with the YAML parser. Take

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.