In my MVC 4 application I am working on ContextMenus with jquery and quite a bit achieved that as well but currently I have been facing issues.
One of my view with the use of contextmenu looks like this:

I need to add some menus(namely Move,Delete,Details) on the right click against each of the element(ex:First Document,Doc1 etc) for which my corresponding razor source is:
<div class="row">
@foreach (var item in Model)
{
<div id="[email protected]" class="col-sm-3 ">
<a class="mylinks">@Html.DisplayFor(m => item.Name, new { @class = "thumbnail" })</a>
<ul id="contextmenu1" class="jqcontextmenu">
<li><a href="#">Item 1a</a></li>
<li><a href="#">Item 2a</a></li>
<li><a href="#">Item 3a</a>
<ul>
<li><a href="#">Sub Item 3.1a</a></li>
<li><a href="#">Sub Item 3.2a</a></li>
<li><a href="#">Sub Item 3.3a</a></li>
</ul>
</li>
</ul>
}
and the script to achieve this is:
jQuery(document).ready(function($){
$('a.mylinks').addcontextmenu('contextmenu1')
})
also I have included a jscontextmenu js file to get it working.
But here my problem is that with this I am able to achieve the right click only for the first element only.I feel that with my document ready function the id for contextmenu1 will be applied to the first element only and in order to assign that against all of the names in the list I need to create some dynamic ids for the ul and then use it in my script .
I tried with some of the possibities using a counter and incrementing it and then assigning the class to the script function but that didnt work. So can anyone suggest the way of achieving this.Thanks in advance.
ulwith idcontextmenu1is generated for each link (via@foreach) which is not valid, as the id should be unique. Try to put it out of@foreach.ul, and attach the contextmenu like this:$('a.mylinks').addcontextmenu($('a.mylinks').next('.jqcontextmenu'));