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 8073241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:16:30+00:00 2026-06-05T14:16:30+00:00

I am using the EditorForModel helper on a class that have a property of

  • 0

I am using the EditorForModel helper on a class that have a property of type ICollection<int> unfortunatlly I can not see my control render in my page.

Here is the sample:

The model view object

public class CopyFromVM
{

    [UIHint("MultiEntityList")]
    public ICollection<int> EntityIds { get; set; }
    ...
}

In the EditorTemplate folder I have the file MultiEntityList.cshtml

@model ICollection<int>


<select name="@ViewData.ModelMetadata.PropertyName" id="@ViewData.ModelMetadata.PropertyName" multiple="multiple" >
 ...
</select>

When the form is render I don’t have any error of any kind. The properties is just ignore from the rendering. So I am suspecting that EditorForModel is ignoring complex type. Looking at the web it should work properly for all type.

thanks for the help.

  • 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-06-05T14:16:31+00:00Added an answer on June 5, 2026 at 2:16 pm

    The following should pick up the custom template from your main view:

    @model CopyFromVM
    @Html.EditorFor(x => x.EntityIds)
    

    The following will not:

    @model CopyFromVM
    @Html.EditorForModel()
    

    The reason for that is because the framework doesn’t recurse into complex object properties. You could modify the Object.cshtml default editor template as explained by Brad Wilson in this blog post (look at the Shallow Dive vs. Deep Dive section towards the end of his post).

    Also make sure that your editor template is placed into the correct folder: ~/Views/Shared/EditorTemplates/MultiEntityList.cshtml and not EditorTemplate as stated in your question (notice the missing s).


    As a side remark, the way you are generating the name and id attributes of your select list inside the editor template is not correct because you are not taking into account the nesting level. Imagine for example that CopyFromVM is used as a property of yet another parent view model. In this case the name of the select will be wrong and the default model binder won’t be able to rehydrate the value: Use the following instead:

    @model ICollection<int>
    <select name="@ViewData.TemplateInfo.GetFullHtmlFieldName("")" id="@ViewData.TemplateInfo.GetFullHtmlFieldId("")" multiple="multiple" >
        ...
    </select>
    

    Well, actually, no, you already have helpers that do this job for you @Html.ListBox. Hardcoding HTML form elements in ASP.NET MVC views seems a pretty fragile process that I would recommend you to avoid.


    And yet another side remark: in order to generate a select list you normally need 2 properties on your view model: one that will hold the selected values and one that will hold all the values. So strongly typing your editor template to ICollection<int> is IMHO a wrong approach here.

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

Sidebar

Related Questions

I have an bool property in a class. And using <%= Html.EditorForModel() %> its
I have a model class that has an AreDuesPaid property that I want only
I have a model I would like to use in a form using EditorForModel()
I have a hidden field on a form that is created in Razor using
I have a class called LocalizedString that is defined in an external library that
I have a model that looks something like this: public class SampleModel { public
Using MVC 3 @html.EditorForModel , the auto-generated template spits out <div class=editor-label>.... <div class=editor-field>....
I have a Model than contains a collection of items that can be modified.
I have done some research and found that I can use: string retUrl =
Lets say I have these class public class BaseClass { public int Id {

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.