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

  • Home
  • SEARCH
  • 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 8145925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:49:13+00:00 2026-06-06T13:49:13+00:00

I am having some difficulty figuring out how to return the selected item in

  • 0

I am having some difficulty figuring out how to return the selected item in my HTML.DropDownList so that upon hitting a submit button, the selected item text will be looked up in my database. Here is what I have:

@{
var selectStaff = "Select LastName + ', ' + FirstName AS Name, StaffID  From StaffList ORDER BY LastName";
var data = db.Query(selectStaff);
var items = data.Select(i => new SelectListItem {
    Text = i.Name
  });
}

And then in the html..

@Html.DropDownList("Select1", items)

This works fine, as my dropdownlist is appearing and is populated, but now upon hitting a submit button, I want to be able to search that text of the selected item in my database. How would I go about doing this?

  • 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-06T13:49:15+00:00Added an answer on June 6, 2026 at 1:49 pm

    If you don’t bind the dropdown to a property on your view model (which would be preferable), you can still get it simply using Request.Form["Select1"] in your controller action.

    If you mean that you want to be able to get the value while still on the razor page, you need to use jQuery (or other javascript) to get the value.

    To get the value with jQuery:

    $(document).ready(function () {
         $("#YourSubmitButtonID").click(function () {
             // Get the value from 'Select1'
             var value = $("#Select1").val();
         });
    });
    

    To do something with the value, you would have to use an ajax function, something like this:

    $.ajax({
        url: '@Url.Action("ActionName", "ControllerName")',
        data: { valueToQuery: $("#Select1").val() },
        success: function (data) {
           // The data is the result
        }
    });
    

    On the controller named ControllerName in this example, you’d have the code that queries the database and returns your result.

    public ActionResult ActionName(string valueToQuery)
    {
         // Do your stuff here
        return Json("your result", , JsonRequestBehavior.AllowGet);
    {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having some difficulty figuring out how to template the following TreeView item
I'm having some difficulty figuring out the best ways to pause and resume my
I'm having some difficulty figuring out what is going on and how to fix
I am having some difficulty in figuring out how to change an applications API
I'm having quite a difficulty, figuring out some strange behavior when looping through symbols
I'm trying to learn jquery and I'm having some difficulty figuring out how to
I am having some difficulty accessing the value of the selected radio button in
So I am having some real difficulty figuring out how to make the following
I'm having some difficulty figuring out a regular expression for stripping part of the
im having some difficulty trying to pull out a specific value from a cookie.

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.