开发者

ASP.NET MVC + Javascript (calling c# code with javascript variables)

is it possible to call c# functions with javascript parameters (from javascript)?

i.e.

<script>

    function someFunction()
    {
       var data = "123";
       var test ="<% AppHelper.GetSomething("+data+"); %>";
    }
</script>
开发者_StackOverflow中文版

Thank You !


No, because ASP.NET code is run and compiled before you get to the javascript. If you want to communicate with the server using javascript, you need to use something like AJAX.

Or you might have a look at server side javascript, to see if that's something you can use.


You could do it but you would have to use an ajax call to hit a URL endpoint which will execute an action. Once the action has been triggered you can do what ever you want in c#.


What you want to do exactly because with jQuery it's very easy to do a call to a controller that return some HTML or data that you can use in javascript. I could give you an exemple if you give more details of what you are trying to do.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜