0

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??

3
  • What do you want to do with that variable? Perhaps there's a different way of doing it. Commented Feb 21, 2014 at 12:11
  • Explain your actual problem including the relevant code parts (keep em short!), there probably is a way to achieve the result in some fashion Commented Feb 21, 2014 at 12:12
  • It is not possible, find other way. Commented Feb 21, 2014 at 12:13

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

i dont want to convert that variable..i just need to pass that value "value" to c# variable a
@bala3569, Still answer is you can't. However you can submits its value to controller action

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.