I have a two dropdown which is related one to onother, i want to fill html dropdownlist for based selected first dropdown
First Dropdown :
@Html.DropDownListFor(model => model.UWI, new SelectList(ViewBag.WellName, "UWI", "PLOT_NAME"), "Select", new { @class = "form-control", @style = "width:250px;font-size:12px", @id = "_UWICOREANALYSIS", required = "required" })
Second Dropdown :
@Html.DropDownListFor(model => model.CORE_ID, new SelectList(ViewBag.WellCore, "CORE_ID", "CORE_ID"), "Select", new { @class = "form-control", @style = "width:250px;font-size:12px", @id = "_COREIDANALYSIS", required = "required" })
$(document).ready(function () {
$("#_UWICOREANALYSIS").change(function () {
var selectedCoreAnalysis = $("#_UWICOREANALYSIS").val();
$.ajax({
type: 'POST',
url: '@Url.Action("GetWellCoreData", "CreateForm")',
data: { uwi: selectedCoreAnalysis },
cache: false,
success: function (data) {
// for (var i in data) {
// alert(JSON.stringify(data[i]));
// }
}
});
return false;
});
});
public ActionResult GetWellCoreData(string uwi)
{
var data = await _iwellcore.GetListDDLWellCoreTableByUwi(uwi);
return Json(data);
}
The dropdown Core_id must fill based on selected dropdown Uwi
Maybe someone can help me.