How to assign Javascript value in Razor?

Asked

Viewed 364 times

2

I have a variable Razor @minhaVarRazor and would like to change its value based on a value obtained from another variable, but which is from Javascript.

function setValue(minhaVarJavaScript){
  @minhaVarRazor = minhaVarJavaScript;
}

Does anyone have any idea?

1 answer

2


That can’t be done. The Razor markup is translated into HTML values on the server itself, and the response the client receives from the network (from the HTTP request) has no Razor markup, only pure HTML/JS/CSS. Since Javascript runs on the client (by the browser), and this one doesn’t "know" Razor (including variable streets), so what you want to do is not possible.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.