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?
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.
精彩评论