Nil Pun
Nil Pun

Reputation: 17383

MVC RAZOR assign javascript variable to C# variable

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)}

Upvotes: 2

Views: 6199

Answers (2)

Mohammed Swillam
Mohammed Swillam

Reputation: 9242

The short and long answer is: NO.

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

Upvotes: 3

SLaks
SLaks

Reputation: 888213

No.

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

You should use AJAX.

Upvotes: 5

Related Questions