jQuery AJAX 範例
js:
<script src="@Url.Content("~/scripts/jquery-3.3.1.min.js")" type="text/javascript"></script>
<script type="text/javascript">
function getDetail(id) {
var DTO = {
'id': id
};
$.ajax({
type: "POST",
url: "@Url.Action("GetBillingAccountDetail", "Payments")",
data: JSON.stringify(DTO),
contentType: "application/json",
beforeSend: function () {
$("#div_dtl").hide()
},
success: setValue,
error: function (xmlhttprequest, textstatus, errorthrown) {
alert("error occured");
}
});
}
function setValue(data) {
$("#td_dtl_cn").html("");
$("#td_dtl_nn").html("");
$("#td_dtl_rn").html("");
$("#td_dtl_dl").html("");
$("#div_dtl").show();
$("#td_dtl_cn").html(data["CompanyName"]);
$("#td_dtl_nn").html(data["Nickname"]);
$("#td_dtl_rn").html(data["ReferenceNo"]);
$("#td_dtl_dl").html(data["DailyLimit"]);
$("#del_link").attr("href", "@Url.Action("DeleteBillingAccount", "Payments")/" + data["BA_ID"])
}
</script>
Function in Controller:
[HttpPost]
public JsonResult GetBillingAccountDetail(int id)
{
BillingAccountList_IndexViewModel.BillingAccountDetails model = BillingAccountListContext.Current.GetBillingAccountDetail(GetBasicData(), id);
return Json(model);
}
jQuery link : https://code.jquery.com/jquery-3.3.1.min.js