on change sir tapos populate ung mga other textboxes na related sa db..
tapos another po pano po ipopulate ung table without ienumerable na idedeclare
given na ung
ID na nakadependent mga values ay region_code:
via angular:
$scope.$watch('data.region_code', function (newValue, oldValue) {
var record = $scope.data;
$http({
method: 'GET',
url: '/api/get_province?id=' + record.region_code,
}).success(function (data, status, headers, config) {
$scope.prov_code_options = data;
}).error(function (data, status, headers, config) {
$scope.message = 'Unexpected Error';
});
});
via knockout:
self.region_code.subscribe(function (newval) {
$.post("/api/get_province", { id: self.region_code() }, function (states) {
self.lib_provinces(states);
});
})
via jquery:
$(document).ready(function () {
$("#region_code").change(function () {
$.ajax({
type: 'POST',
url: '@Url.Action("get_province", "api")', // we are calling json method
dataType: 'json',
data: { id: $("#region_code").val() },
success: function (states) {
// states contains the JSON formatted list
// of states passed from the controller
$.each(states, function (i, state) {
$("#lib_provinces").append('<option value="' + state.Name+ '">' + state.Id+ '</option>');
}); // here we are adding option for States
},
error: function (ex) {
alert('Failed to retrieve data.' + ex);
}
});
return false;
})
});
sa likod eto lang:
[Route("api/get_province")]
public IHttpActionResult GetProvinces(string id)
{
return Json(db.lib_province.Where(x => x.region_code == id).Select(x => new { Id = x.prov_code, Name = x.prov_name }));
}