Hi I have some code like:
<ul>
<li data-id="1"></li>
<li data-id="2"></li>
<li data-id="3"></li>
</ul>
In a script:
$('li').click(function () {
window.location.href = '@Url.Action("View", "People", new { id = $(this).data('id')})';
});
What I’m trying to achieve is that when a user clicks a list item it redirects to:
People/View/id
where id is the id attribute on the list item.
Trouble is I can’t work out what is wrong with the code.
The part $(this).data(‘id’) has a squiggly underline and says:
‘,’ or ‘}’ expected.
Sorry this is probably a really dumb question but I can ‘t corrently work it out.
You can not mix server and clientside code. They do not interact with each other.
I am guessing you need to do something like this: