How to use JavaScript variable in Razor?

前端 未结 1 1074
盖世英雄少女心
盖世英雄少女心 2020-12-20 07:36

I try to pass my JS variable into razor, my script fragment:

 select: function (event, ui) {                            
   var docID = ui.item.DoctorCode;

         


        
相关标签:
1条回答
  • 2020-12-20 08:11

    I try to pass my JS variable into razor

    This sentence makes strictly no sense at all.

    Razor is a view engine used by the ASP.NET MVC framework running on the server to produce some HTML template.

    javascript on the other hand is a client side language running on the client. Once the HTML template is rendered to the client and javascript starts to execute there's no longer such notion as Razor.

    If you want to pass some javascript variable to the server you have a couple of options:

    • make an AJAX call to the server
    • set the value of this variable in some hidden field inside a form and submit this form
    • use window.location.href to redirect to the server and passing the variable as query string parameter
    • store the javascript variable in a cookie which will be sent to the server on subsequent requests
    0 讨论(0)
提交回复
热议问题