@Html.DropDownList("drpcountry", (SelectList)ViewBag.Country, "Select Country", new { @class = "form-control", @required = "required" })
<script type="text/javascript">
$('#drpcountry').change(function () {
var Id = $('#drpcountry').val();
if (Id != "") {
$.ajax({
url: '/Admin/GetAllState',
dataType: "json",
type: "POST",
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({ Id: Id }),
async: true,
processData: false,
cache: false,
success: FillSubject,
error: function (xhr) {
}
});
}
});
function FillSubject(result) {
var StateList = result.StateList;
var select = $("#drpstate");
if (select != null) {
select.empty();
select.append($('<option/>', {
value: "",
text: "Select State"
}));
for (i = 0; i < StateList.length; i++) {
select.append($('<option/>', {
value: StateList[i].Id,
text: StateList[i].LocationName
}));
}
}
}
</script>
========================================================
// List All Satete
public JsonResult GetAllState(Guid Id)
{
List<Location> StateList = LocationManager.GetAll().Where(s => s.CountryId == Id).OrderBy(s => s.LocationName).ToList();
var result = new { StateList = StateList };
return (Json(result, JsonRequestBehavior.AllowGet));
}
No comments :
Post a Comment