on selection of Authority, district is binding but my issue is I want to fetch tehsil and on fetching tehsil, and according to authority and tehsil, villages shown
Authority*
Html.DropDownListFor(x => x.SelectedDeptCode, Model.Departments, "----Select Authority-----", new { id = "deptcode", class = "form-control", onchange = "getdistrict()" })
Html.ValidationMessageFor(model => model.SelectedDeptCode, "", new { class = "text-danger" })
District *
Html.TextBoxFor(model => model.districtname, htmlAttributes: new { id = "distcode", class = "form-control" })
Html.ValidationMessageFor(model => model.districtname, "", new { class = "text-danger" })
Amit MohantyPosted Jun 19, 2024, 10:07 AM
Have a look on the below code, this may help you.
Jayraj ChhayaPosted Jun 19, 2024, 9:10 AM
To populate a dropdown based on the selection in another dropdown in ASP.NET MVC, you can use JavaScript and AJAX to fetch the data dynamically from the server.
First, you need to add the necessary HTML markup for the dropdowns in your view. In this case, you have three dropdowns: Authority, District, and Tehsil. The Authority dropdown triggers the population of the District dropdown, and the District dropdown triggers the population of the Tehsil dropdown.
Next, you need to write the JavaScript function
getDistricts()that will be triggered when the Authority dropdown's value changes. This function will make an AJAX call to the server to fetch the districts based on the selected authority.In your controller, you need to define the
GetDistrictsByDeptaction method that will return the districts based on the selected authority.