I have a link like this
<a class="viewp" href="#">@data.name</a>
and I would like to call a jquery ajax this way
$(document).ready(function ()
{
$('.viewp').click(function (id)
{
var responseUrl="~/click?id="+id;
$.ajax(
{
type: "GET",
data:id,
url:responseUrl,
success:success
});
});
});
But I don't know how the id
of the @data.name
is passed into the jquery function.
If I replace the above link's href
with href="~/click?id=@data.id"
then that is supposed to load the whole page not some specific region and clearly ajax doesn't work also.
[UPDATE]
By id
I would mean the id
primary key of my sql table and I am using webmatrix to code my simple web page. My database table looks like this create table x(id, name)
You can do something like this:
And then in the function you can get the id:
use
$(this)
to get the currently clicked a tag and then get theid
attribute value of that.I haven't got what exactly you mean
if it is like
< a class="viewp" href="#" id="someId" >@data.name< /a>
if you want to get id of it
then
$(this).attr("id");
if you want to get text @data.name
then
$(this).text();