我已经从Index.cshtml视图向PrintPreview方法发出了Ajax调用,该方法存在于MasterList Controller中,我也传递了参数。 Index方法也存在于MasterList控制器中 从PrintPreview方法返回视图时,调用将转到PrintPreview.cshtml页面,但页面未加载,即不在浏览器中显示,而在浏览器中显示的Index.cshtml页面 请帮忙。
在这里输入代码
$('#printbtn').click(function () {
$.ajax({
type: 'POST',
url: '@Url.Action("PrintPreview", "MasterList")',
data:
{ saleorderIdList: JSON.stringify(saleorder_id),
orderIdList:JSON.stringify(order_id) },
});
});
public ActionResult PrintPreview(string saleorderIdList, string orderIdList)
{
var locationIdOfLoginUser = Convert.ToInt32(Session["LocationId"]);
ViewBag.loccationName = Session["LocationName"];
ViewBag.locationType = Session["LocationType"];
JavaScriptSerializer serializer = new JavaScriptSerializer();
IEnumerable<int> saleOrderIds = new int[] { };
IEnumerable<int> orderIds = new int[] { };
if (saleorderIdList != null)
{
saleOrderIds = serializer.Deserialize<IEnumerable<int>>(saleorderIdList);
}
if (orderIdList != null)
{
orderIds = serializer.Deserialize<IEnumerable<int>>(orderIdList);
}
MasterListService masterListService = new MasterListService();
var ordercollection = masterListService.GetSelectedorders(locationIdOfLoginUser, saleOrderIds, orderIds);
return View(ordercollection);
}
答案 0 :(得分:0)
数据必须与预期的“形状”相匹配。您正在传递单个对象(具有2个属性),但它需要一个列表(即JSON数组)。
您应该更改帖子而不是传递数组:
data: passresult: [{ saleorderIdList: JSON.stringify(saleorder_id),
orderIdList:JSON.stringify(order_id) }],
如果失败,只是作为测试,将您的操作更改为此操作并查看是否已命中(对于您的现有数据):
public ActionResult PrintPreview(MasterListDTO passresult)