如何从jquery获取值到c#object mvc [英] How to get value from jquery to c# object mvc

查看:48
本文介绍了如何从jquery获取值到c#object mvc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@{string test = string.Empty;}

@{test=
      <text>
      $('#__RequestVerificationToken').val()
        </text>
      ;}





我尝试过:



只想从Element获取值并将其传递给c#object



What I have tried:

Just want to fetch value from Element and pass it to c# object

推荐答案

('#__ RequestVerificationToken')。val()
< / text >
;}
('#__RequestVerificationToken').val() </text> ;}





我尝试过:



只想从Element获取值并将其传递给c#object



What I have tried:

Just want to fetch value from Element and pass it to c# object


不,你不能将javascript变量分配给C#变量。因为razor变量是服务器变量,但是javascript变量是客户端变量。



当服务器获取视图请求时,它会创建仅包含HTML,CSS和Javascript代码。当视图仍然在服务器上时,Javascript代码确实存在,它将仅由浏览器执行(客户端再次)。这意味着更少。



是的,您可以将服务器变量分配给javacript:

No, you can't assign javascript variables to C# variable. Because razor variable are server variables but javascript variables are client side variable.

When the server gets a request for a view, it creates the view with only HTML, CSS and Javascript code. The Javascript code do exist when the view is still on the server, it will be executed by the browser only (Client side again). It is meaning less.

Yes, you can assign server variables to javacript:
<script> var myJsVariable = '@ViewBag.MyVariable' </script>


这篇关于如何从jquery获取值到c#object mvc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆