how to get view data value
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.
精彩评论