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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:38:24+00:00 2026-05-25T09:38:24+00:00

In an ASP .NET MVC Razor view, I have a dropdown list as follows:

  • 0

In an ASP .NET MVC Razor view, I have a dropdown list as follows:

@Html.DropDownListFor(model => model.SelectedDeviceModel, Model.DeviceModelList)

DeviceModelList is just a SelectList.

How can I dynamically fill the DeviceModelList depending on a client side action like a button click or another drop down selection using Javascript/jQuery/Ajax?

  • 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-25T09:38:25+00:00Added an answer on May 25, 2026 at 9:38 am

    You could externalize this dropdown into a partial:

    @model MyViewModel
    @Html.DropDownListFor(model => model.SelectedDeviceModel, Model.DeviceModelList)
    

    then in your main view include it inside some container:

    @model MyViewModel
    ...
    <div id="ddlcontainer">
        @Html.Partial("Foo", Model)
    </div>
    ...
    

    then you could have a controller action which takes some parameter and based on its value it renders this partial:

    public ActionResult Foo(string someValue)
    {
        MyViewModel model = ... go ahead and fill your view model
        return PartialView(model);
    }
    

    Now the last part is to send the AJAX request to refresh the drop down list when some event occurs. For example when the value of some other ddl changes (or something else, a button click or whatever):

    $(function() {
        $('#SomeOtherDdlId').change(function() {
            // when the selection of some other drop down changes 
            // get the new value
            var value = $(this).val();
    
            // and send it as AJAX request to the newly created action
            $.ajax({
                url: '@Url.Action("foo")',
                type: 'POST',
                data: { someValue: value },
                success: function(result) {
                    // when the AJAX succeeds refresh the ddl container with
                    // the partial HTML returned by the Foo controller action
                    $('#ddlcontainer').html(result);
                }
            });
        });
    });
    

    Another possibility consists into using JSON. Your Foo controller action would only return some Json object containing the new key/value collection and in the success callback of the AJAX request you would refresh the drop down list. In this case you don’t need to externalize it into a separate partial. For example:

    $(function() {
        $('#SomeOtherDdlId').change(function() {
            // when the selection of some other drop down changes 
            // get the new value
            var value = $(this).val();
    
            // and send it as AJAX request to the newly created action
            $.ajax({
                url: '@Url.Action("foo")',
                type: 'POST',
                data: { someValue: value },
                success: function(result) {
                    // when the AJAX succeeds refresh the dropdown list with 
                    // the JSON values returned from the controller action
                    var selectedDeviceModel = $('#SelectedDeviceModel');
                    selectedDeviceModel.empty();
                    $.each(result, function(index, item) {
                        selectedDeviceModel.append(
                            $('<option/>', {
                                value: item.value,
                                text: item.text
                            })
                        );
                    });
                }
            });
        });
    });
    

    and finally your Foo controller action will return Json:

    public ActionResult Foo(string someValue)
    {
        return Json(new[] {
            new { value = '1', text = 'text 1' },
            new { value = '2', text = 'text 2' },
            new { value = '3', text = 'text 3' }
        });
    }
    

    For a similar example you may take a look at the following answer.

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

Sidebar

Related Questions

I have a partial view in an ASP.NET MVC app: @Html.Partial(_Comments, Model) I want
I'm attempting to integrate jqGrid into an ASP.NET MVC 4 Razor view and have
I have the following in my ASP.Net MVC 3 Razor View @foreach (var item
I am working on asp.net MVC 3 application. I have created a Razor view
I have created a Razor view in my asp.net MVC 3 application. It is
I am using ASP.NET MVC 3 with the Razor view engine . I have
I'm having an odd problem with asp.net MVC razor view. I want my model
I am using ASP.NET MVC 3 with the razor view engine. I have the
I have created an asp.net mvc 3 razor view and added data annotation attributes
I have a list menu in Asp.net MVC Razor engine Masterpage. While trying some

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.