How to pass variable from jquery to code in c#

前端 未结 2 511
醉梦人生
醉梦人生 2021-01-16 08:13

in my page i have an int variable name mySerial and i want to pass a value from a script

mySerial =ui.item.Serial is not working

2条回答
  •  野的像风
    2021-01-16 08:47

    you could pass value from your jquery to controller action like this ...

    $(document).ready(function()
    {
        var postdata  = { name: "your name", Age: "your age" };// you can pass control values 
        $.ajax({
            ur: /home/index,
            data: postdata,
            success: function(returndata)
                 {
                    // do something here for the return data...
                  }
             });  
    });
    

    in your controller

    public ActionResult PostedDAta(string myname, string myage)
    {
                // do somethign here and return Json back to Jquery code
                return Json(data,JsonRequestBehaviour.AllowGet);  
    }
    

提交回复
热议问题