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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:30:57+00:00 2026-06-09T17:30:57+00:00

I feel like I’m taking crazy pills. I have a dropdownlist for a view

  • 0

I feel like I’m taking crazy pills. I have a dropdownlist for a view that reads from our database all of the wine producers we have. I want to set the selectedValue to a particular ID driven by the referring page. I can see it picks up the selectedValue in debug, I see the selected value populated (906 for this example), but it doesn’t set the dropdownlist to the correct value when the page is rendered, it always defaults to 1 for the default value. I’ve tried creating the selectList in razor as opposed to my controller, but nothing works. Any help on this would be appreciated, I’m guessing it is something small.

Controller:

        if (User.IsInRole("admin"))
        {
            if (ID != 0)
            {
                ViewBag.ProducerSelect = new SelectList(db.Producers.OrderBy(p => p.Name), "ProducerID", "Name", ID);
            }
            else
            {
                ViewBag.ProducerSelect = new SelectList(db.Producers.OrderBy(p => p.Name), "ProducerID", "Name");
            }
        }

View:

if (User.IsInRole("producereditor"))
{
    <h3>@ViewBag.ProducerName</h3>
}
    else
{
<div class="editor-label">
    @Html.LabelFor(m => m.Wine.ProducerID, "Producer")
</div>
<div class="editor-field">
    @Html.DropDownListFor(m => m.Wine.ProducerID, ViewBag.ProducerSelect as SelectList)
</div>
}

Tried the below but no success:

         ViewBag.ProducerSelect = new SelectList(from p in db.Producers
                                                    orderby p.Name
                                                    select new { p.ProducerID, p.Name }
                                                    , "ProducerID", "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-06-09T17:30:58+00:00Added an answer on June 9, 2026 at 5:30 pm

    I figured this out. I had ViewModel.wine.ProducerID elsewhere on the page in a hidden field, and that defaults to 1, so I just assigned that to passed in value, and it worked great. I knew it was something like that. Thanks!

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

Sidebar

Related Questions

Feel like I'm going a bit nutty here. I have a detail view with
Feel like this should be something easy that I'm missing. I have a table
I feel like I'm re-inventing the wheel, and that there is a good chance
I feel like I understand the difference between require and require_dependency (from How are
I feel like I'm missing something here, but I have this datagrid which when
I feel like I must have missed the right thread, because this seems like
I feel like this is something that Google should be able to solve for
I feel like there's something about grids that I'm missing, but I can't find
I feel like I'm way overthinking this problem, but here goes anyway... I have
I feel like this should have a simple answer, but I can't find it.

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.