pass parameter from java script to c# in razaor page

1 Answer 1343 Views
Grid
Mohamad Javad
Top achievements
Rank 2
Iron
Iron
Iron
Mohamad Javad asked on 12 Dec 2022, 02:22 PM

hi 

i need pass Parameter myTicket_Id from java script to c# in razaor page .

my code is :


<script>
                        function onChange(e) {
                            var selectedRows = this.select();
                            var dataItem = this.dataItem(selectedRows[0]);

                            var myTicket_Id=dataItem.Ticket_Id

                            console.log(dataItem.Ticket_Id);

                        };
                    </script>
                    

                    @{

                        HttpContext.Session.Set("Ticket_Id", myTicket_Id);

                        Response.Redirect("/Ticket?id="  + myTicket_Id );
                    }
thanks
Mohamad Javad
Top achievements
Rank 2
Iron
Iron
Iron
commented on 15 Dec 2022, 09:47 AM

Can anyone answer me?

1 Answer, 1 is accepted

Sort by
0
Accepted
Stoyan
Telerik team
answered on 20 Dec 2022, 04:22 AM

Hi Mohamad Javad,

The Razor syntax is executed on server while JavaScript is executed on the browser. This difference is why JavaScript variables are not directly accessible to Razor.

That being said you can store the needed values in Cookies and then access these Cookies through Razor .

Alternatively, send an Ajax request to the server to make the needed variables available there.

I remain open if more questions related to our products arise.

Regards,
Stoyan
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Grid
Asked by
Mohamad Javad
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Stoyan
Telerik team
Share this question
or