开发者

Use javascript variables as arguments in class method in C#

开发者 https://www.devze.com 2023-03-07 14:21 出处:网络
How can I use use javascript variables in C# cod开发者_StackOverflow社区e? or How can I assign C# variable value in javascript (from another javascript variable) in cshtmlDo you realize that your we

How can I use use javascript variables in C# cod开发者_StackOverflow社区e?

or

How can I assign C# variable value in javascript (from another javascript variable) in cshtml


Do you realize that your web pages are first processed on the server by IIS, using C#, and then transferred to the client, where JavaScript is executed?

This means that you technically can use your C# variables in your JavaScript code by something like

<script type="text/javascript">
var productID = @Model.ProductID;
</script>

but not vice versa.

Maybe you should consider using AJAX to make the additional requests to the server without the need to refresh the page.


You can use hidden variables. values can be assigned from js --> c# and vice versa. Or you can create properties in c# and access/assign values to them from js.

0

精彩评论

暂无评论...
验证码 换一张
取 消