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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:58:26+00:00 2026-06-10T05:58:26+00:00

I have a service layer that exposes a method, which returns me a List,

  • 0

I have a service layer that exposes a method, which returns me a List, called GetStates.

public List<StateObject> GetStates()

My State Object is just a custom object I have created:

public class StateObject
{
    public int stateId { get; set; }
    public string description { get; set; }
    public Boolean isDefault { get; set; }
}

In my models, I am trying to create a model that will be used for my display and modification screen of a task. One thing this will be used for is handling the display and selection of a Drop down box, which will give a list of States available for my Task. So, my model looks something like this (Removed properties we don’t car about – it’s a bit bigger than this:

public class TaskModifyModel
{
    public int stateId { get; set; }
    public string state { get; set; }

    public SelectList states { get; private set; }

    public TaskModifyModel()
    {

        states = new SelectList(
            (new ReferenceService().GetStates()),
            "stateId",
            "description",
            1);

    }
}

So, stateId holds the selected state, state holds the text description of the selected state. In the constructor, I am attempting to create a states SelectList for the view… and populate it.

In the view, I then try to display the Drop Down List:

@Html.DropDownListFor(m=>m.stateId, new SelectList(Model.states, "stateId", "description", Model.priorityId))

This is failing, dismally.

DataBinding: ‘System.Web.Mvc.SelectListItem’ does not contain a property with the name ‘stateId’.

I have searched, and I thought I was doing this the right way, but the error says I am not.. clearly. 🙂 Could someone guide me on why it’s not working, and also, is this the right way to do things?

Edit:
After assistance below, it’s now working. If I am creating a new task (taskId==0), then I have to get the default value of the dropdown, as stored in my database…. So, is this clean? This is my working constructor for the object:

public TaskModifyModel()
{
var referenceService = new ReferenceService();
var p = referenceService.GetPriorities();
var s = referenceService.GetStates();

    var defaultP = (from a in p where a.isDefault select a).FirstOrDefault();
    var defaultS = (from a in s where a.isDefault select a).FirstOrDefault();

    priorities = new SelectList(
        (p),
        "priorityId",
        "description"
        );
    priorityId = taskId == 0 ? defaultP.priorityId : priorityId;

    states = new SelectList(
        s,
        "stateId",
        "description");
    stateId = taskId == 0 ? defaultS.stateId : stateId;

}

Is it OK?

  • 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-10T05:58:27+00:00Added an answer on June 10, 2026 at 5:58 am

    Your public SelectList states { get; private set; } is already a SelectList so you don’t need to cast it again in your View.

    Try this instead:

    @Html.DropDownListFor(m=>m.stateId, Model.states)
    

    And in your ViewModel, remove the parameter “SelectedValue”. The @Html.DropDownListFor will initialize the dropdown to the right value.

    public class TaskModifyModel
    {
        public int stateId { get; set; }
        public string state { get; set; }
    
        public SelectList states { get; private set; }
    
        public TaskModifyModel()
        {
    
            states = new SelectList(
                (new ReferenceService().GetStates()),
                "stateId",
                "description");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WCF Service that exposes a method GetCustomers(). The internals of the
I have a service layer method that I want to expose that should return
I have a service, business and data access layer. In which layer should I
I currently have service classes that look something like this public class UserService :
I have a service layer that I would like to convert into a webservice.
I have this scenario in my 3-tier app with a Service Layer that serves
I have a WCF service that exposes a bunch of methods that return business
I am using WCF DataService I have a method: [OperationContract] public List<string> GetAges() {
We have an application in which we have created a service layer with most
I have a class, say Provider, that exposes its funcationality to the above service

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.