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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:05:02+00:00 2026-05-27T23:05:02+00:00

Requirment: I have a drop down and a table on my cshtml page. The

  • 0

Requirment: I have a drop down and a table on my cshtml page. The drop down displays a list of vendors and the details corresponding to selected vendor are displayed in table. I am submitting the form using jquery when the value of the drop down changes.

Problem: How to cath selected value of drop down in controller?

Code:

@Html.DropDownList("VendorList", new SelectList(Model.vendorList, "vendorId", "vendorName"))

@using (Html.BeginForm("VendorDetails", "VendorLookUp", FormMethod.Post, new { id = "vendorDetailsForm" }))
{
    <div class="margin-10-top" >
      <table id= "VendorDetail" class="VendorDetail">

        ........ details of vendor.........

      </table>
   </div>
}

<script type="text/javascript" charset="utf-8">
$(document).ready(function () {
    $('#VendorList').change(function () {
        $('#vendorDetailsForm').submit();
    });
}); 
</script>

the code in my controller is:

    [AcceptVerbs("POST")]
    public ActionResult SearchResult(FormCollection collection)
    {
        try
        {
            string vendorName = collection["searchItem"].ToString();

            vendorName = vendorName.Trim();
            List<Vendor> vendorList = Queries.compiledVendorQuery(dbContext, vendorName).ToList<Vendor>();

            if(vendorList.Count() == 0)
                return View("EmptySearch");

            Vendor selectedVendor = vendorList[0];

            VendorDetails vendorDeatils = Queries.compiledVendorDetailsQuery(dbContext, selectedVendor.vendorId.ToString()).FirstOrDefault();

            VendorResult vendorResult = new VendorResult();
            vendorResult.vendorList = vendorList;
            vendorResult.vendorDetails = vendorDeatils;

            return View(vendorResult);
        }
        catch (Exception e)
        {
            return View("EmptySearch");
        }
    }

    [AcceptVerbs("POST")]
    public ActionResult VendorDetails(FormCollection collection)
    {
        **here comes the control after postback
        require value of the selected item** 

        Vendor selectedVendor = ?? 

        VendorDetails vendorDeatils = Queries.compiledVendorDetailsQuery(dbContext, selectedVendor.vendorId.ToString()).FirstOrDefault();

        VendorResult vendorResult = new VendorResult();
        vendorResult.vendorDetails = vendorDeatils;

        return View(vendorResult);
    }
  • 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-27T23:05:03+00:00Added an answer on May 27, 2026 at 11:05 pm

    Since you’re not really using the FormCollection, you could just use an int (or whatever the ID is on your model) in your action method:

    [HttpPost]
    public ActionResult VendorDetails(int vendorId = 0)
    {
        Vendor selectedVendor = // Load from your data source using vendorId
        ...  // Do the rest of your work
    }
    

    In your HTML, move your @Html.DropDownListFor() into your form, rename it to the argument name, then submit the form as normal. Since the display doesn’t seem to have any affect on what gets sent to the server, I would pull this out and just leave the @Html.DropDownListFor() in the form:

    @using (Html.BeginForm("VendorDetails", "VendorLookUp", FormMethod.Post, new { id = "vendorDetailsForm" }))     
    {
        @Html.DropDownList("vendorId", new SelectList(Model.vendorList, "vendorId", "vendorName"))
    }
    
    <div class="margin-10-top" >
        <table id= "VendorDetail" class="VendorDetail">
            ........ details of vendor.........
        </table>
    </div>
    
    <script type='text/javascript'>
        $(document).ready(function () {        
            $('#vendorId').change(function () {
                $('#vendorDetailsForm').submit();
            });
        });
    </script>
    

    Edit

    Take a look at this article about MVC’s model binding for an idea of how vendorId gets injected from the submitted form. Basically, the binder will match property names with the name attribute (by default) to your model. In this case, our model is just an int.

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

Sidebar

Related Questions

Requirment: I have a drop down list on my view page, displaying a list
I have a set of drop down lists (8 in all). All drop downs
The scenario is I have got 2 dropdown list and a table in which
I have to create the Jquery Grid that have check boxes and drop down.
We have a requirment which requires to have an Handler that is extended from
I have requirement like, suppose I have a 'property' table which has 'ListingKey' field
I have an ambitious requirement for an asp.net 2.0 web page that contains a
I am facing a problem with jquery. I have a div with 4 drop
I have a ASP.Net web page with a grid view. I want to filter
My requirement is to select a value from a drop down and fetch the

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.