开发者

how to get view data value

开发者 https://www.devze.com 2023-01-14 04:25 出处:网络
I have <%var test = ViewData[\"test\"];%> <ul class= \"list\" id = \"<%test;%>\"> but having error message:

I have

 <%var test = ViewData["test"];%>

 <ul class= "list" id = "<%test;%>">

but having error message:

Only assignment, call, increment, decr开发者_如何转开发ement, and new object expressions can be used as a statement

What is wrong?


Your output block needs to use <%= %> or <%: %> if you want it encoded, like this:

<ul class="list" id="<%=test%>">

Though, unless you need the variable all over the place, just use <%= %> on the original ViewData["test"], it's a bit cleaner, at least to me.


 <ul class= "list" id = "<%=ViewData["test"]%>">


try this...

<ul class= "list" id = "<%=test%>"> 

...you were missing the '=' symbol before 'test' & added an extra ';' after it.

0

精彩评论

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