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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:00:43+00:00 2026-06-01T03:00:43+00:00

I have a dropdownlist that is being populated by a sql server, I am

  • 0

I have a dropdownlist that is being populated by a sql server, I am using Visual Studio 2010, cshtml, with razor as well as using the MVC pattern to create this project. What I am trying to do is when someone selects a value from the dropdown list on change it will update the page with information about that book.

I need help with the three things below:

  1. user selects a book from the dropdownlist how to get the Book Name back to the controller
  2. The server (retrieve the information from the server about the book) and
  3. Back to view to be displayed.

I started with getting the dropdown poplulated.

My View looks like this

BookName: @Html.DropDownList("BookName", ViewData["BookName"] as IEnumerable<SelectListItem>, new { id = "UserSelectedValue" })

My Controller:

public ActionResult Index()
    {
       ViewData["BookName"] = new SelectList(_context.BookName.Select(a => a.Book_Name).Distinct());
                    return View();
    }
  • 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-01T03:00:44+00:00Added an answer on June 1, 2026 at 3:00 am

    A dropdown list can’t cause the page to post back to your controller on its own. You need to do one of two things:

    1. Add a submit button so that the user changes the dropdown and then clicks a button to view the results.
    2. Use javascript to submit the form on the element’s change event.

    Either way, you will need to wrap the dropdown/submit button in a form.

    Option 1

    <form>
        BookName: @Html.DropDownList("BookName", ViewData["BookName"] as  IEnumerable<SelectListItem>, new { id = "UserSelectedValue" })
        <input type="submit" value="Show results" />
    </form>
    

    Option 2

    <script type="text/javascript">
        // assuming you're using jQuery
        $(function() {
            $('#UserSelectedValue').change(function() {
                $(this).parent('form').submit();
            });
        });
    </script>    
    <form>
        BookName: @Html.DropDownList("BookName", ViewData["BookName"] as  IEnumerable<SelectListItem>, new { id = "UserSelectedValue" })
        <input type="submit" value="Show results" />
    </form>
    

    Your controller code would then become something like:

    public ActionResult Index(string bookName)
    {
       ViewData["BookName"] = new SelectList(_context.BookName.Select(a => a.Book_Name).Distinct());
    
       if (!string.IsNullOrWhiteSpace(bookName))
       {
           ViewData["Books"] = _context.BookName.Where(b => b.Book_Name == bookName).ToList();
       }
       return View();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a dropdownlist that populates from the sql server database. populating the list
I have a dropdownlist that is being populated from a database. That is working
I have a dropdown box that is being populated by a filtered list of
I have a DropDownList that is populated with the primary key of Table A.
I have a dropdownlist that has 4 columns but only 3 are 'visible' the
If I have a DropDownList control that makes up part of a CompositeControl how
I have an ASP.NET DropDownList control that retrieves the first and last name from
I have a dropdownlist inside a gridview, that is loaded from a datasource when
I have a CompositeControl that contains a DropDownList. I have set the AutoPostBack property
I have the following code that sets a cookie: string locale = ((DropDownList)this.LoginUser.FindControl(locale)).SelectedValue; HttpCookie

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.