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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:58:50+00:00 2026-06-12T03:58:50+00:00

I have a 2 Dropdownlistfor in html, dropdownlistfor Country and dropdownlistfor state. Im using

  • 0

I have a 2 Dropdownlistfor in html, dropdownlistfor Country and dropdownlistfor state. Im using MVC, I want to be the output like this, If I change the Selected Country, the state of the selected country will be filled in the dropdownlistfor state. Im getting the data of country and state from database, and in the table of state there is a field for countryId. Thanks for help.

here is the sample Code in Html.

            <div class="fieldBlock">
                <div><label>Country</label>&nbsp;*</div>
                <div>@Html.DropDownListFor(model => model.Country.Id, Model.CountrySelectList, new { @class = "width305", @id = "ddlCountry" })</div>
                @Html.HiddenFor(model => model.Country.Name) @Html.HiddenFor(model => model.Country.Abbreviation)
                <div>@Html.ValidationMessageFor(model => model.Employee.StateId)</div>
            </div>

            <div class="fieldBlock">
                <div>@Html.LabelFor(model => model.Employee.StateId, "State/Province")&nbsp;*</div>
                <div>@Html.DropDownListFor(model => model.Employee.StateId, Model.CountryStateProvinceSelectList, new { @class = "width305" })</div>
                <div>@Html.ValidationMessageFor(model => model.Employee.StateId)</div>
            </div>
  • 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-12T03:58:51+00:00Added an answer on June 12, 2026 at 3:58 am

    Try this

    In View

    <script type="text/javascript">
         $(function() {
                $("#ddlCountry").change(function() {
                    var selectedItem = $(this).val();
                    var ddlStates = $("#ddlState");
                    var statesProgress = $("#states-loading-progress");
                    statesProgress.show();
                    $.ajax({
                        cache: false,
                        type: "GET",
                        url: "@(Url.Action("SomeAction", "SomeController"))",
                        data: { "countryId": selectedItem},
                        success: function (data) {
                            ddlStates.html('');
                            $.each(data, function(id, option) {
                                ddlStates.append($('<option></option>').val(option.id).html(option.name));
                            });
    
                        },
                        error:function (xhr, ajaxOptions, thrownError){
                            alert('Failed to retrieve states.');
    
                        }  
                    });
                });
            });
        </script>
    
    
    <div class="fieldBlock">
        <div><label>Country</label>&nbsp;*</div>
        <div>@Html.DropDownListFor(model => model.Country.Id, Model.CountrySelectList, new { @class = "width305", @id = "ddlCountry" })</div>
        @Html.HiddenFor(model => model.Country.Name) @Html.HiddenFor(model => model.Country.Abbreviation)
        <div>@Html.ValidationMessageFor(model => model.Employee.StateId)</div>
    </div>
    
    <div class="fieldBlock">
        <div>@Html.LabelFor(model => model.Employee.StateId, "State/Province")&nbsp;*</div>
        <div>@Html.DropDownListFor(model => model.Employee.StateId, Model.CountryStateProvinceSelectList, new { @class = "width305", @id = "ddlState" })</div>
        <div>@Html.ValidationMessageFor(model => model.Employee.StateId)</div>
    </div>
    

    In Controller

    public ActionResult SomeAction(string countryId)
    {
         //perform your action here
         var states = _stateProvinceService.GetStateProvincesByCountryId(country.Id).ToList();
         var result = (from s in states
                       select new { id = s.Id, name = s.GetLocalized(x => x.Name) }
                      ).ToList();
    
       return Json(result, JsonRequestBehavior.AllowGet);
    } 
    

    NOTE: Check whether Id is properly bind to dropdowns and I have written dummy code in action to get state.

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

Sidebar

Related Questions

I have a MVC view that contains some dropdowns like this : <%: Html.DropDownListFor(model
I have a partial view that has something like this <%= Html.DropDownListFor(m => m.SelectedProductName,
I have a dropdownlist that looks like this: @Html.DropDownListFor( x => x.Attribute.AttributeID, new SelectList(Model.Attributes,
When I have a DropDownList that relevant to Model of view like this: @Html.DropDownListFor(model
i have two select using as a dropdownlist for country/state everything works as i
I have small design question about html.DropDownListFor() How can I change width of html.DropDownListFor()
I have the following dropdownlist in mvc <%= Html.DropDownListFor(c => c.Address.Id, new SelectList(Model.Addresses, id,
I am using ASP.NET MVC 2. Html.DropDownListFor and Html.TextAreaFor automatically get red borders when
I'm displaying a drop down menu using the following syntax: @Html.DropDownListFor(model => model.Country, new
So I have this on the front end: <%= Html.DropDownListFor(m => m.FixedComponent.PaymentBusinessDayConvention, DropDownData.BusinessDayConventionList(), ,

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.