I just tried the same thing as you and it works great.
<script language="javascript"> var a = '<%=Model.userName %>'; alert(a); </script>
In my controller, I have the following:
public ActionResult Login() { LoginFormViewModel loginFVM = new LoginFormViewModel(); loginFVM.userName = "slappy"; return View(loginFVM); }
All of the above assumes that you are trying to get the model value in javascript from your view.
Also, make sure your view inherits from your model, otherwise it would not know what temp is.
Hope this helps.
source share