Reputation: 2129
I want to create a div from every object in my model, and I need to give them unique IDs for the onclick-method. How do I do this? I tried to put myid inside <%= %> as I read somewhere, it does not work.
This is my code:
@foreach(var r in Model){
var myid = r.ToString();
<p class="expand-one" onclick="showhide('<%= myid %>')" onmouseover="" style="cursor: pointer;">@r.ToSection.Name</p>
<table id=@myid class="content-one">
<tr>
......................
..................
Upvotes: 1
Views: 1471
Reputation: 1511
Usually I use this, so you can try
<p class="expand-one" onclick="showhide('@(myid)')"></p>
Upvotes: 1
Reputation: 6565
You should be able to use Razor's @
in the same manner you use it in @r.ToSection.Name
:
<p class="expand-one" onclick="showhide('@myid')"></p>
Upvotes: 3