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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:41:05+00:00 2026-05-29T15:41:05+00:00

I have a Razor page with a drop down list inside a form: @using

  • 0

I have a Razor page with a drop down list inside a form:

@using (Html.BeginForm("ProductsByOwners", "Report", FormMethod.Post, new { @id = "ProductsByOwners" }))
{            
    @Html.Label("Choose product owner: ")
    @Html.DropDownList("OwnerList", (SelectList)ViewBag.OwnerList, new { @onchange = "this.form.submit();" })    
}

The selected value of my SelectList is not being carried over to the DropDownList. I’ve debugged and stepped through the code and found that (SelectList)ViewBag.OwnerList evaluates properly and has the expected value selected, but the resulting HTML does not have any of the option tags selected.

Can anyone see what I’m doing wrong here?

UPDATED

Here is how the SelectList is created in my action:

ViewBag.OwnerList = new SelectList(ListUtils.ProductOwners(), "Key", "Value", values["OwnerList"]);

The result has the value indicated by values["OwnerList"] selected.

Thanks!

  • 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-29T15:41:05+00:00Added an answer on May 29, 2026 at 3:41 pm

    You are not using the DropDownList helper properly. In order to create a dropdownlist you need 2 things:

    1. a scalar property to bind to the selected value when the form is submitted
    2. a collection to bind the options to

    In your example you have only one of those 2 things (the second). Your first argument is called OwnerList and you have ViewBag.OwnerList passed as second argument.

    So:

    @Html.DropDownList(
        "SelectedOwnerId", 
        (SelectList)ViewBag.OwnerList, 
        new { @onchange = "this.form.submit();" }
    )
    

    Obviously I would recommend you using strongly typed views ans view models. And obviously get rid of the weakly typed ViewBag/ViewData/ViewCrap.

    So start by designing a view model to meet the requirements of your view (which from what you have shown so far is to display a dropdownlist):

    public class OwnerViewModel
    {
        [DisplayName("Choose product owner: ")]
        public string SelectedOwnerId { get; set; }
    
        public IEnumerable<SelectListItem> OwnerList { get; set; }
    }
    

    then a controller:

    public class ReportController: Controller
    {
        public ActionResult ProductsByOwners()
        {
            var model = new OwnerViewModel
            {
                // preselect the second owner
                SelectedOwnerId = "2",
    
                // obviously those come from your database or something
                OwnerList = new[] 
                {
                    new SelectListItem { Value = "1", Text = "owner 1" },
                    new SelectListItem { Value = "2", Text = "owner 2" },
                    new SelectListItem { Value = "3", Text = "owner 3" },
                }
            };
            return View(model);
        }
    
        [HttpPost]
        public ActionResult ProductsByOwners(OwnerViewModel model)
        {
            ...
        }
    }
    

    and you have a corresponding strongly typed view:

    @model OwnerViewModel
    @using (Html.BeginForm("ProductsByOwners", "Report", FormMethod.Post, new { id = "ProductsByOwners" }))
    {            
        @Html.LabelFor(x => x.SelectedOwnerId)
        @Html.DropDownListFor(
            x => x.SelectedOwnerId, 
            Model.OwnerList, 
            new { onchange = "this.form.submit();" }
        )
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page in Asp.Net MVC using the Razor syntax. In the page
I have a Razor layout MVC3 page as below: <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML
MVC 3 VB.NET applicaiton... Using express checkout with html razor view. I have tried
I had created a webpage using asp.net mvc3 razor. I have two master pages
I have the following on a razor page: @{ Session[CurrentUrl] = Request.Url.ToString(); } I
With ASP.NET MVC3 (Razor) I have a simple page that loads a jQuery UI
I have online form builder appplication in ASP.NET MVC3 with Razor views. It is
Hi I have a htmleditor like this: @{ ViewBag.Title = Home Page; } @Html.DevExpress().HtmlEditor(
I have a MVC 3 application with Razor. The form is data driven and
I used to have something like this: We suggest you read our @Html.ActionLink(help page,

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.