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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:22:23+00:00 2026-05-13T17:22:23+00:00

I have a model that looks something like this: public class SampleModel { public

  • 0

I have a model that looks something like this:

public class SampleModel
{
    public static SampleModel Create()
    {
        return new SampleModel
        {
            Boolean = true,
            // set several more properties...
            Colors = new SelectList(new[] { "Red", "Green", "Blue" }, "Green")
        };
    }

    public bool Boolean { get; set; }
    // define several more properties...
    public SelectList Colors { get; set; }
}

I’m letting ASP.NET MVC automatically scaffold the properties using Html.DisplayForModel() for my Details view and Html.EditorForModel() for my Edit view.

Results:

  • The Edit view works great. Colors shows up as a menu with three items (Red, Green, and Blue), and Green is selected by default.

  • For the Details view, however, I get “False True False”, which is apparently a list of the IsSelected value for each item of the menu. That is definitely not want I want. I would like it to just display “Green”.

  • A further problem is that, if I try to do UpdateModel(sampleModel) in my controller, I get the error, “No parameterless constructor defined for this object.” This is presumably because Colors is a SelectList, and there is no parameterless constructor for SelectList, so it can’t complete the binding.

So, I think I understand what the problems are, but I could really use a good solution for this scenario, which seems to come up a lot when you have models objects with foreign keys.

Some questions:

  1. How do I get Colors to show up as a menu for the Edit view but as just a simple string value (e.g., “Green”) in the Details view?
  2. How can I prevent a “no parameterless constructor” error when updating a model that contains a SelectList?
  3. If my Model/ViewModel actually contained a foreign key, ColorId, instead of Colors, what would be the best practice for getting the Details view to show the name of the current color and the Edit view to show a menu containing all the color names listed in the Color table of my database. If it helps, I’m using LinqToSql (SqlMetal) to generate my model classes.
  • 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-13T17:22:24+00:00Added an answer on May 13, 2026 at 5:22 pm

    Your problems all stem from the fact that you’re exposing a SelectList as a model property. Depending on the exact situation, I’d probably do something like:

    1. Create 3 separate model classes: one “domain” model consisting of your LinqToSql objects (or wrappers around them) and two view models, one for the Details view and one for the Edit view.

    2. The Details view model should contain the currently selected color name. The Details action would set this property, either using the FK relationship in your domain objects or by manually looking up the details for the selected color.

    3. The Edit view model should contain a property for the selected color’s ID. It should also contain a select list of available color options, with the selected value set to the currently selected ID.

    4. The Edit action that handles the form post should accept an instance of the Edit view model and should map those changes onto the domain model. Since the selected color is exposed a simple property, rather than a select list, it’s easy to validate and map back onto the business object.

    If your situation is very simple you might be able to get away with a single view model for both View and Edit, or even passing the domain object directly to the Details view. In any case, as long as you remove the SelectList from your model and expose the selected color as a simple ID then you should be OK.

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

Sidebar

Ask A Question

Stats

  • Questions 314k
  • Answers 314k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If by VSS you mean Visual Source Safe, then you… May 13, 2026 at 11:01 pm
  • Editorial Team
    Editorial Team added an answer A file descriptor is a low-level integer "handle" used to… May 13, 2026 at 11:01 pm
  • Editorial Team
    Editorial Team added an answer Take a look at http://:50030 or http://:50030/jobhistory.jsp (at the bottom.… May 13, 2026 at 11:01 pm

Related Questions

I have a question regarding the method i am using for doing Business Rule
I have a class like this: public class Contest { List<ContestTeam> Teams { get;
I have a C module which is created by the Real-time Workshop based on
I have a controller method that looks like this: [AcceptGet] public ActionResult Index(SecurityMatrixIndexViewModel model)
I am creating a simple aspnetmvc cart application and have defined classes similar to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.