learning
learning

Reputation: 11725

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, decrement, and new object expressions can be used as a statement

What is wrong?

Upvotes: 0

Views: 2770

Answers (3)

belugabob
belugabob

Reputation: 4460

try this...

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

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

Upvotes: 1

Alex Reitbort
Alex Reitbort

Reputation: 13696

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

Upvotes: 2

Nick Craver
Nick Craver

Reputation: 630379

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.

Upvotes: 4

Related Questions