我正在通过选中复选框来发送多个email/SMS
。而当我在我的JavaScript函数中接收数据时。但是当我把它传递给行动方法记录计数显示,但所有的数据都是空的。下面是我的代码截图here控制器中的JSON数据为空
这是我的模型:
public class BulkEmailSendViewModel
{
public BulkEmailSendViewModel()
{
Candidates = new List<CandidateData>();
}
public List<CandidateData> Candidates { get; set; }
public string Body { get; set; }
public string Subject { get; set; }
}
public class CandidateData
{
public string Email { get; set; }
public string CandidateId { get; set; }
public string Phone { get; set; }
public string CandidateName { get; internal set; }
}
//选取所有选中的复选框
$("#bulkAction").change(function() {
var ddlId = $("#bulkAction").val();//to get sms or email
var chk_arr = $('.checkCandidate:checkbox:checked');
var chklength = chk_arr.length;
var json = '';
$('.checkCandidate:checkbox:checked').each(function() {
if (this.checked) {
var Phone = $(this).attr("candidatePhone");
var CandidateId = $(this).attr("candidateId");
var Email = $(this).attr("candidatEmail");
var item = '{\"Phone\":\"' + Phone + '\","CandidateId\":\"' + CandidateId + '\",\"Email\":\"' + Email + '\",\"CandidateName\":\"\"},';
json += item;
}
});
json = "[" + json.substr(0, json.length - 1) + "]";
SendBulkEmail(json);
});
我的javascript:
function SendBulkEmail(jsonObj) {
alert(jsonObj);
if (jsonObj.length > 0) {
var send = "/Utility/Notifications/BulkEmail";
$(".modal-title").text("Send Email");
//var data = {
// Candidates: eval(jsonObj)
//};
$.get(send, { bulkEmailSendViewModel: eval(jsonObj) }, function (result) {
$("#C_modal_body").html("");
$("#C_modal_body").html(result);
});
}
else {
$.alert("Email not found for this candidate.");
// e.stopPropagation();
}
}
我的控制器:
public PartialViewResult BulkEmail(List<CandidateData> bulkEmailSendViewModel)
{
BulkEmailSendViewModel bulkDetail = new BulkEmailSendViewModel();
return PartialView(bulkDetail);
}
为什么我的所有值都为空即使我在javascript函数中?
你尝试'JSON.stringify({bulkEmailSendViewModel:EVAL(jsonObj)})'。也考虑做出Post请求。 – User3250
通过将json作为一个字符串而不是一个对象数组来构建你的硬盘。 – James
打开Chrome,按f12,进入网络选项卡,点击保存日志。现在,当SendBulkEmail $ .get发送时,发送的头是什么?它有效的JSON? https://jsonlint.com/ – phpmeh