javascript - 无法通过弹出窗口将对象传递给控制器方法
问题描述
从 ajax 调用中,我得到一些数据,我想通过单击按钮传递到另一个窗口。我成功接收了数据,但是当该数据被传递时,在控制器方法参数中接收的值为 null。
<script>
$(document).ready(function () {
$('#btnSalesInAmount').click(function () {
var data = {
toDate: $('#todatepicker').val(),
fromDate: $('#fromdatepicker').val(),
customerId: $('#CustomerId').val()
};
$.ajax({
type: 'Get',
url: '/Reports/SalesInAmount' + '?toDate=' + data.toDate + '&fromDate=' + data.fromDate + '&customerId=' + data.customerId,
data: data,
success: function (data) {
window.open("/Reports/SalesInAmountView" + '?salesInAmount=' + data, 'SalesInAmountViewWindow', "features");// the data is not received by controllers method
}
});
});
});
</script>
在控制器中
public ActionResult SalesInAmountView(SalesInAmount salesInAmount) // parameter value is null
{
return View();
}
该模型
public class SalesInAmount
{
public DateTime SalesDt { get; set; }
public int SalesSl { get; set; }
public int CustomerSupplyId { get; set; }
public string CustomerSupplyNm { get; set; }
public double TotalSalesByCustomer { get; set; }
public double TotalDiscount { get; set; }
public double TotalVat { get; set; }
public double TotalSales { get; set; }
public List<SalesInAmount> List { get; set; }
}
解决方案
尝试这个 ,
简化您的数据集,
var Param1= $('#ID').val();
var Data = JSON.stringify({ Data1 : Param1, . . });
阿贾克斯
$.ajax({
url: '@Url.Action("Action_Name", "Controller_Name")',
dataType: "json",
contentType: "application/json; charset=utf-8",
type: "POST",
data: Data,
cache: false,
success: function (data) {
});
}, error: function (request, status, error) {
}
});
}
控制器
public JsonResult Action_Name(string Data1 , . . )
{
return Json(Some_Json);
}
注意:此控制器返回 Json 结果,这取决于要求。
推荐阅读
- python - 单个 pandas 数据帧上的 Fuzzy Wuzzy 逻辑,用出现次数最多的实例替换相似值
- c++ - 如何编辑分配的变量?
- javascript - 如何使用 Webpack 添加主题 javascript 文件?
- yaml - 无法在 Azure DevOps 管道中激活 conda
- c# - 数据类型问题
- ruby-on-rails - current_user 从反应方面为零,Rails 应用程序
- web2py - 为什么更新使用 db.table[id] 语法检索到的记录不起作用?
- r - R中闪亮应用程序的本地主机目录在哪里显示本地pdf文件?
- c# - 如何在 InArgument 中获取 '*' 字符而不是任何字符串
- excel - 从列表框中的多个列中选择单个项目