I am trying to do something like send an array from js to controller using ajax request. And after some processing I want to redirect to that action with result. Following is the code...
JavaScript
var arr = ['1','2','3','4'];
function CheckOut()
{
$.ajax({
url: '/Admin/AdminPanel/ProceedToBill',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({ morder: arr }),
success: function (result) {
}
});
}
Controller`
[HttpPost]
public ActionResult ProceedToBill(int[] morder)
{
// morder = [deal_id , quantity]
List<MyModels.CartModel> cart = new List<MyModels.CartModel>();
MyModels.CartModel item = new MyModels.CartModel();
for (int i = 0; i < morder.Length; i+=2 )
{
item.deal = db.Deals.Find(morder[i]);
item.qty = morder[i + 1];
item.price = item.deal.Price * item.qty;
cart.Add(item);
}
return View(cart);
}
So, the problem is there that's an ajax request not a simple one. So I cant return a View. What should I do here now. Please help me.