html 使用AJAX POST请求来调用控制器操作(在页面加载时和在下拉列表中选择项目时),获取返回的布尔值,设置observabl
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 使用AJAX POST请求来调用控制器操作(在页面加载时和在下拉列表中选择项目时),获取返回的布尔值,设置observabl相关的知识,希望对你有一定的参考价值。
[HttpPost, Core.Authorization.ValidateAntiForgeryToken]
public JsonResult doesClientOrDescendentScreenVolunteers(long clientId)
{
try
{
bool doesAnyClientScreenVolunteers;
if (clientId < 0)
{
var clientList = clientService.getClientHierarchy(clientId);
doesAnyClientScreenVolunteers =
clientList.Any(x => x.AccountUseTypeId == (int) AccountUseTypeEnum.Volunteerism);
}
else
{
var client = clientService.findById(clientId);
doesAnyClientScreenVolunteers = client.AccountUseTypeId == (int)AccountUseTypeEnum.Volunteerism;
}
return Json(doesAnyClientScreenVolunteers, JsonRequestBehavior.AllowGet);
}
catch (Exception)
{
var message = $"Error while checking to see if client {clientId} has Employee screening.";
log.ErrorFormat(message);
return Json(new { success = false, message }, JsonRequestBehavior.AllowGet);
}
}
self.selectedAccount = ko.observable(self.getSelectedFromList(model.ChildAccounts));
self.selectedAccount.subscribe(function () {
self.doesClientOrDescendentScreenVolunteers(); //calls it when selection made from dropdown
self.persistCurrentClientId();
});
self.displayInterestedSection = ko.observable();
self.doesClientOrDescendentScreenVolunteers = function () {
$.ajax({
type: "POST",
url: $("#doesClientOrDescendentScreenVolunteers").attr("href"),
data: { clientId: self.selectedAccount().Value },
success: function(result) {
self.displayInterestedSection(result);
},
error: function (response) {
handleSubmitError(response);
$("#sortLoading").modal("hide");
}
});
};
self.doesClientOrDescendentScreenVolunteers(); // calls it on page load
<!-- ko if: displayInterestedSection -->
<div style="width: 280px; display: inline-block;">
<h4>
<span data-bind="text:interestedCount" class="filterCount"> </span> Interested
Candidates - <a href="#" style="text-decoration: underline;" data-bind="click: $root.handleFilterInterestedFromLink.bind()">View All</a>
</h4>
<ul data-bind="foreach: interestedResults" class="unstyled clearfix">
<li>
<a href="#" class="btn btn-link" data-bind="click: $root.handleFilterFromLink.bind($data), attr: { 'class': bgResult }, visible: $root.showLink($data)">
<span data-bind="text:count" class="filterCount"> </span> <span data-bind="text: bgResult"></span>
</a>
</li>
</ul>
</div>
<!-- /ko -->
以上是关于html 使用AJAX POST请求来调用控制器操作(在页面加载时和在下拉列表中选择项目时),获取返回的布尔值,设置observabl的主要内容,如果未能解决你的问题,请参考以下文章
JavaScript之Ajax-2 Ajax(使用Ajax发送get请求使用Ajax发送post请求)
Ecstore中如何调用发起Ajax请求
来自 ASP NET Web API 的 CORS 阻止 Ajax POST 调用 - 对预检请求的响应未通过访问控制检查
当 jQuery Ajax 调用完成时控制请求
请求正文为空,POST 节点 js ajax 调用 json Web 令牌
浅谈Ajax的get 和post的区别