C# 与 JS 之间传值在 cshtml页面中
@{ string It = "sss"; var IT = 1; } @functions{ string Mod = "ajssaioi"; public string Itmodel = "aisaoaopp"; public string GetToken() { return "ssdhksdnksjdjosij"; } } <h2>@ViewData["Title"].</h2> <h3>@ViewData["Message"]</h3> <div class="row"> <input type="button" id="antiforgery" value="Antiforgery" /> <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js"></script> <script> $("#antiforgery").click(function () { var m1 = '@Itmodel'; var m2 = '@Mod'; var m3 = '@It'; var m4 = @IT; var m5 = '@GetToken()'; alert(m1); alert(m2); alert(m3); alert(m4); alert(m5); }); </script> </div>