2

Is it possible to assign javascript variable to c# variable in mvc razor view? e.g.

<script>@cSharpVar=javascriptVar;</script>

Also, is it possible to pass javascript variable to c# method? e.g.

@{var test=Utility.MethodName(javascriptVar,cSharpVar)}

2 Answers 2

5

No.

C# runs on the server; Javascript runs on the client.
It does not make sense to have them interact.

You should use AJAX.

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

Comments

3

The short and long answer is: NO.

All these scenarios should be covered by AJAX calls to the server

Comments

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.