How to pass variable from jquery to code in c#

前端 未结 2 533
醉梦人生
醉梦人生 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:46

    You could pass this variable as query string parameter to some controller action:

    
    

    and the Foo action:

    [HttpPost]
    public ActionResult Foo(string mySerial)
    {
        ... do something with the serial here
    }
    

    Another possibility is to perform a redirect if you don't want to use AJAX:

    
    

    Or maybe I misunderstood your question and you want to assign your javascript variable to some value coming from the view model? In this case:

    
    

提交回复
热议问题