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

  • Home
  • SEARCH
  • 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 6942271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:59:37+00:00 2026-05-27T12:59:37+00:00

When I try to bind in an MVC 3 view (using an @Html.DropDownList helper)

  • 0

When I try to bind in an MVC 3 view (using an @Html.DropDownList helper) to a select list based on an IEnumerable< X >, where X is a custom class I created rather than a framework class, I get the error “DataBinding: ‘MyCustomNamespace.MyCustomClass’ does not contain a property with the name ‘MyProperty’.”. I do not get an error if I use a SelectListItem or a KeyValuePair in place of my custom class in the IEnumerable – in that case it works fine. I am guessing that the issue may be that my custom class is not known in the Html.DropDownList helper and hence can’t be accessed there? But I thought this was supposed to operate using reflection and the property names I specified during SelectList definition, so that would not be necessary… ?

Here is a simplified version of my code:

// In .cshtml file:
@Html.DropDownList("cmbSection", (SelectList)ViewBag.Section)

// In Controller:
List<MyCustomClass> filters = new List<MyCustomClass>();
MyCustomClass testItem1 = new MyCustomClass { MyProperty = "AAA"};
MyCustomClass testItem2 = new MyCustomClass { MyProperty = "BBB"};

filters.Add(testItem1);
filters.Add(testItem2);

return new SelectList(filters, "AAA", "MyPropertyName", "MyPropertyName");

// Elsewhere:
public class MyCustomClass
{
    public string MyProperty
}

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-27T12:59:37+00:00Added an answer on May 27, 2026 at 12:59 pm

    controller

    //your code starts
    List<MyCustomClass> filters = new List<MyCustomClass>();
    MyCustomClass testItem1 = new MyCustomClass { MyProperty = "AAA"};
    MyCustomClass testItem2 = new MyCustomClass { MyProperty = "BBB"};
    
    filters.Add(testItem1);
    filters.Add(testItem2);
    //your code ends here
    
    var items= (from item in filters
                    select new SelectListItem
                    {
                        Value= item.MyProperty 
                        Text= item.MyProperty 
                    }).toList();
    
       ViewBag.items= items;
    

    View

    @Html.DropDownList("MyDropDownList", items)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i try to bind data to model with Html.EditorFor() helper and submit, but model
I am try to bind the dropdowmlist using jquery. But is showing some error.
I'm trying to bind a function with a non-existent class. I will try to
I try to bind value from input select to attribute selectedValue in controller. This
I try to bind XAML ListBoxItem using Code but doesn't seem work In my
I have an MVC app via SharpArch. In the view I have: Html.DropDownListFor(x =>
Using sqlite and building queries, they all work fine until I try to bind
I am using version 2011.2.914 of the controls. Whenever I try to bind data
I try to bind an IPv6 server socket in Java 1.6 on Windows 7,
When I try to bind port 80 to a socket in c, i always

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.