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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:35:48+00:00 2026-05-14T16:35:48+00:00

I have an edit page with a Html.DropDownList in it….I cant show the dropdownlist

  • 0

I have an edit page with a Html.DropDownList in it….I cant show the dropdownlist value it always shows up with Select instead i want to make the dropdown show an item as selected based on a model value say Model.Mes_Id… Any suggestion how it can be done…

       <p>
            <label for="MeasurementTypeId">MeasurementType:</label>
         <%= Html.DropDownList("MeasurementType", // what should i give here?)%>
            <%= Html.ValidationMessage("MeasurementTypeId", "*") %>
        </p>

EDIT: It has the list items but i want to show a value selected in the edit view…

   public ActionResult Edit(int id)
    {
        var mesurementTypes = consRepository.FindAllMeasurements();
        ViewData["MeasurementType"] = mesurementTypes;
        var material = consRepository.GetMaterial(id);
        return View("Edit", material);
    }

My repository method,

public IEnumerable<SelectListItem> FindAllMeasurements()
        {
            var mesurements = from mt in db.MeasurementTypes
                              select new SelectListItem
                              {
                                 Value = mt.Id.ToString(),
                                 Text= mt.Name
                              };
            return mesurements;
        }
  • 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-14T16:35:48+00:00Added an answer on May 14, 2026 at 4:35 pm

    Set the selected item when you create the IEnumerable<SelectListItem>.

    Personally I would create a specialized viewmodel for the form but going by your code, do something like:

    public ActionResult Edit(int id)
    {
        //Put this first
        var material = consRepository.GetMaterial(id);
        //pass in your selected item
        var mesurementTypes = consRepository.FindAllMeasurements(material.MeasurementTypeId);
        ViewData["MeasurementType"] = mesurementTypes;
    
        return View("Edit", material);
    }
    

    Then change your repository method to something like:

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

    HTHs,
    Charles

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

Sidebar

Related Questions

I have an html page that I want to edit. I want to remove
I have some CRUD routing: /news/{page} // public /news/new // private /news/{slug}/show //public /news/{slug}/edit
I have an edit page with url example.com/product/edit/11 Now if the validation is false
i have a small problem, i am creating a edit page in my asp.net
In my ASP.NET MVC app, I have a fairly complex edit page which combines
I have a page where the user can edit various content using buttons and
I have a form on a page where the user has inputs to edit
I have an asp.net page. There is a button Edit on the bottom that
I won't want to have edit any working sets. I just want a way
I have 3 (Edit) mutually exclusive IEnumerables that I want to iterate over. I

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.