user3504028
user3504028

Reputation: 77

Syntax Error when I try to access model data with razor

Bit of a newbie to MVC, when I try to access my username property of my viewmodel, I get a syntax error.

 @section scripts {
        <script type="text/javascript">
               var userName = @Model.UserName;
        </script>
  }

Upvotes: 1

Views: 211

Answers (1)

Jonathan Hiben
Jonathan Hiben

Reputation: 553

This is a known issue: actually Visual Studio thinks there is syntax error but there's not! You've got some solutions:

  • put "", like var userName = "@Model.UserName"
  • ignore the error. Your view will compile because it is not a real one
  • maybe through a function

Upvotes: 1

Related Questions