简体   繁体   中英

how to pass a value from javascript variable to c# variable in asp.net mvc

Here i have a value in javascript variable and i need to pass this value to c# variable.How to pass this value while loading that cshtml file?

<script type="text/javascript">
var str="value"; 
</script>

in razor view

var a=str; //c#

Any suggestion??

Short answer is You can't

You wont be able to pass/convert JavaScript variable to a Razor variable. Razor variable is handled by Razor engine where as JavaScript on the other hand is a client side language running on the client.

Razor is a view engine used by the ASP.NET MVC framework running on the server to produce some HTML template.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM