0

i am new in mvc3 razor my prob is :

i have this actionResult method that can receive variables from jquery method

why my variables comes NULL

csharp :

public ActionResult GetOrdersSP(int? StoreId, int? SupplierId)
        {
            bool count = false;

            var model = _storeOrderService.GetStoreSuppOrders(StoreId, SupplierId);

            if (model.Count() > 0)
            {
                count = true;
                return Json(count, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(count, JsonRequestBehavior.AllowGet);
            }
        }

and this is my jquery

$.fn.GetCount = function (data) {
        var storeid = $('#StoreId').val();
        var Supplierid = $('#Supplierid').val();
        if (ValidateCreateOrder('#StoreId', '#Supplierid')) {
            alert(storeid);
            alert(Supplierid);

            $.ajax(
                {
                    url: '<%: Url.Action("GetOrdersSP", "StoreOrder")%>',
                    type: 'json',
                    data: { StoreId: $('#StoreId').val(),
                        SupplierId: $('#SupplierId').val()
                    },
                    success: function (json) {

                        //should popup the modal 
                        alert(true);
                    }
                });
        }
    }

please note that the storeid and supplierid are displayed correctly in the alert

thanks

  • instead of using int try using string – COLD TOLD Jul 17 '12 at 05:51
  • 1
    Could u just use something like firebug sort of to check whether the request contains the post data ?? – bhuvin Jul 17 '12 at 05:57
  • Where are you calling the `GetCount` method? – Darin Dimitrov Jul 17 '12 at 06:02
  • @DarinDimitrov - Dude just for my reference - how will it affect the ajax call ?? – bhuvin Jul 17 '12 at 06:06
  • For example if you call this method in the click of an anchor or a submit button and forget to return false from the handler to cancel the default action, this default action could execute leaving no time for the AJAX call to run. The browser will simply redirect to the given action. – Darin Dimitrov Jul 17 '12 at 06:08

1 Answers1

0

I think you need to convert your data to json and parse it on actionResult.

See this post Pass a parameter to a controller using jquery ajax

Community
  • 1
  • 1
Andrey Ashgaliyev
  • 157
  • 1
  • 4
  • 15