I have given Ajax call from Index.cshtml view to PrintPreview method which is present in MasterList Controller and i have also passed parameters. The Index method also present in MasterList controller But while returning view from PrintPreview method call is going to PrintPreview.cshtml page but the page is not loading i.e not displaying in browser and Index.cshtml page displaying in browser please help.
$('#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);
}
In above code i got both array saleOrderIds and orderIds also in ordercollection i got List as expected for view
call is going to that PrintPreview View also in that view i got all list as i passed to that view but That PrintPreview.cshtml page is not displaying instead Index.cshtml page is displaying from where ajax call is passed
PrintPreviewthen it needs to bereturn PartialView(ordercollection);and in the ajaxsuccess:callback, update the DOM. If thats not what you want, do a normal submit/post to a method and redirect.