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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:53:14+00:00 2026-05-14T18:53:14+00:00

I use a dropdownlist in one of my create.aspx but it some how doesnt

  • 0

I use a dropdownlist in one of my create.aspx but it some how doesnt seem to work…

public IEnumerable<SelectListItem> FindAllMeasurements()
    {
        var mesurements = from mt in db.MeasurementTypes
                          select new SelectListItem
                          {
                             Value = mt.Id.ToString(),
                             Text= mt.Name
                          };
        return mesurements;
    }

and my controller,

 public ActionResult Create()
    {
      var mesurementTypes = consRepository.FindAllMeasurements().AsEnumerable();
     ViewData["MeasurementType"] = new SelectList(mesurementTypes,"Id","Name");
     return View();
    } 

and my create.aspx has this,

<p>
  <label for="MeasurementTypeId">MeasurementType:</label>
    <%= Html.DropDownList("MeasurementType")%>
     <%= Html.ValidationMessage("MeasurementTypeId", "*") %>
   </p>

When i execute this i got these errors,

DataBinding: 'System.Web.Mvc.SelectListItem' does not contain a 
 property with the name 'Id'.
  • 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-14T18:53:14+00:00Added an answer on May 14, 2026 at 6:53 pm

    In your controller you are creating a new SelectList from IEnumerable<SelectListItem> which is not correct because you’ve already specified the Value and Text properties.

    You have two options:

    public ActionResult Create()
    {
        var mesurementTypes = consRepository.FindAllMeasurements();
        ViewData["MeasurementType"] = mesurementTypes;
        return View();
    }
    

    or:

    public ActionResult Create()
    {
        ViewData["MeasurementType"] = new SelectList(db.MeasurementTypes, "Id", "Name");
        return View();
    }
    

    There’s also a third and preferred way using strongly typed view:

    public ActionResult Create()
    {
        var measurementTypes = new SelectList(db.MeasurementTypes, "Id", "Name");
        return View(measurementTypes);
    }
    

    and in the view:

    <%= Html.DropDownList("MeasurementType", Model, "-- Select Value ---") %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use httpservice with object result to load data on dropdownlist. Some time the
I would like to use jQuery in ASP.NET User Control. Can some one tell
I am trying to create a subclass of asp:DropDownList so I can use asp:DdlNoEventValidation
I want to use a ComboBox with the DropDownList style (the one that makes
i want to use jquery's function on dropdownlist's OnTextChanged Event. but i dont know
I have an ASP.NET webform on which I use a DropDownList control to allow
I am quite confused with how to effectively use the Html.DropDownList helper for ASP.NET
i use this code to fill dropdownlist ViewData[projectType] = new SelectList (_dataManager.Project.ProjectTypeList(), Id, Name);
i use jquery serialize() with asp.net server controls. <asp:DropDownList ID=ddFirmaAd runat=server Width=180 Height=25> </asp:DropDownList>
I have a server dropdownlist in an Ajax updatepanel. When I use the mouse

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.