开发者

MVC RAZOR assign javascript variable to C# variable

开发者 https://www.devze.com 2023-03-03 18:48 出处:网络
Is it possible to assign javascript variable to c# varia开发者_运维百科ble in mvc razor view? e.g.

Is it possible to assign javascript variable to c# varia开发者_运维百科ble in mvc razor view? e.g.

<script>@cSharpVar=javascriptVar;</script>

Also, is it possible to pass javascript variable to c# method? e.g.

@{var test=Utility.MethodName(javascriptVar,cSharpVar)}


No.

C# runs on the server; Javascript runs on the client.
It does not make sense to have them interact.

You should use AJAX.


The short and long answer is: NO.

All these scenarios should be covered by AJAX calls to the server

0

精彩评论

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