1

I can't get the following to work:

var percent = <% Model.Percent; %>

I am sending a Model to the view from the controller...I'm getting the error:

Only assignment, call, increment, decrement, and new object expressions can be used as a statement

Am I being extremely stupid?

1
  • +1 for asking a coherent question, and providing a relevant exception. Commented Oct 3, 2011 at 6:09

1 Answer 1

5

Replace:

var percent = <% Model.Percent; %>

With:

var percent = <%= Model.Percent %>

The <% nugget simply means, "run this code as a C# statement". It doesn't actually render any value. <%= on the other hand evaluates the C# expression, and converts it to a string and renders it. This way, it'll print out the percent in your javascript.

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

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.