-1

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.

tereško
  • 58,060
  • 25
  • 98
  • 150
Adnan Inayat
  • 27
  • 10
  • you can try this: http://stackoverflow.com/questions/17095443/how-to-use-simple-ajax-beginform-in-asp-net-mvc-4 – Mahedi Sabuj Sep 20 '15 at 20:23
  • `content type: "application/json; charset=utf-8", data: JSON.stringify({ 'morder' : 'arr' }),...` <-- quotes in json. – wazz Sep 21 '15 at 05:16

2 Answers2

1

That's not what Ajax is for. Your Ajax calls should return JSON data. If you want to redirect the user after a successful HTTP call then you'll need to do it client side with Javascript, e.g. window.location = redirect_uri.

Bill Ravdin
  • 249
  • 2
  • 6
0

I am done. Simply I just received the complete DOM in my result variable in success method. I updated the dom with that result...:)

Adnan Inayat
  • 27
  • 10