开发者

Using <% asp tags in javascript not working?

开发者 https://www.devze.com 2023-04-09 21:20 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消