Я хочу заполнить # 2, используя событие onchange # 1 и используя ajax для вызова действия в контроллере, но он возвращает 'undefined'.
Я пытался JsonResultBehavior.AllowGet, но он устарел в asp.netcore
VIEW:
<div class="col-md-4" style="padding-bottom: 1em;">
<label for="ddlCorporateName">Corporate Name
</label>
<select id="ddlCorporateName" class="form-control" required></select>
</div>
AJAX / jquery:
<script type = "text/javascript">
function GetSelectedStatus(ddlStatus) {
var id = ddlStatus.options[ddlStatus.selectedIndex].innerHTML;
var selectedValue = ddlStatus.value;
//window.location.href = '@Url.Action("PopulateCorporateName",
"POMultipleApprovalSummary") / ' + id;
$(function() {
var ddlCorporateName = $("#ddlCorporateName");
ddlCorporateName.empty().append('<option selected="selected"
value = "0"
disabled = "disabled" > Loading..... < /option>');
$.ajax({
type: "POST",
url: '@Url.Action("PopulateCorporateName", "POMultipleApprovalSummary") / ' + id,
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(reponse) {
ddlCorporateName.empty().append('<option
selected = "selected"
value = "0" > Select All < /option>');
$.each(reponse, function() {
ddlCorporateName.append('<option selected="selected"
value = "' + this.CorporateName + '" > ' + this.CorporateName + '</option>');
});
},
failure: function(response) {
alert(response.responseText);
},
error: function(response) {
alert(response.responseText);
}
});
});
}
</script>
КОНТРОЛЛЕР:
[HttpPost][Produces("application/json")]
public JsonResult PopulateCorporateName(string id) {
IPage page = new IPage(_accessor);
string status = id;
string accesslevel = string.Empty;
string CustName = string.Empty;
if (page.UserPageAccessLevel == Models.Constant.UserAccessLevel.BUHead) {
if (status == "Printed") {
accesslevel = "BU01PRINT";
} else if (status == "Pending SAM") {
accesslevel = "BU01";
} else if (status == "Pending Approval") {
accesslevel = "BU01PENDINGAPPROVAL";
} else if (status == "Approved SAM") {
accesslevel = "APPROVEDSAM";
} else if (status == "Rejected SAM") {
accesslevel = "REJECTEDSAM";
}
} else {
if (page.UserPageAccessLevel == Models.Constant.UserAccessLevel.ApproverLevel3) {
accesslevel = "AP03";
} else if (page.UserPageAccessLevel == Models.Constant.UserAccessLevel.ApproverLevel4) {
accesslevel = "AP04";
} else if (page.UserPageAccessLevel == Models.Constant.UserAccessLevel.ApproverLevel2) {
accesslevel = "AP02";
} else if (page.UserPageAccessLevel == Models.Constant.UserAccessLevel.ApproverLevel5) {
accesslevel = "AP05";
}
if (status == "All Pending") {
accesslevel = accesslevel + "ALL";
} else if (status == "Pending Approval") {} else if (status == "Rejected SAM") {
accesslevel = "REJECTEDSAM";
} else if (status == "Approved SAM") {
accesslevel = "APPROVEDSAM";
}
}
try {
List < Models.POMultipleApprovalOverride > items2 = new
List < Models.POMultipleApprovalOverride > ();
Hashtable htParameters2 = new Hashtable();
htParameters2.Add("POMultipleGroup", "");
htParameters2.Add("AccessLevel", accesslevel);
htParameters2.Add("PONumber", "");
htParameters2.Add("CorporateName", "Select All");
items2 = (List < Models.POMultipleApprovalOverride > ) BusinessRules.Corporates.itemPOAppMultiple(htParameters2);
return Json(items2);
} catch(Exception e) {
return Json(e.Message);
}
}
Я просто хочу заполнить "CorporateName"элемент из объекта Items2.