我希望能够使用 Html.ActionLink() 将下面代码中每个项目的 id 传递给 jQuery 函数。
@foreach (var item in Model)
{
if (item.AppointmentStatus == "P")
{
<div class="appointment-main-block" role="menuitem" tabindex="20">
<div class="appointment-heading">
@Html.DisplayFor(modelItem => item.Speciality)
</div>
<div class="appointmenttitle">
Date
<br />
<br />
Clinician
<br />
<br />
Location
</div>
<div class="appointmentdata">
@Html.DisplayFor(modelItem => item.AppointmentDate)
<br />
<br />
@Html.DisplayFor(modelItem => item.ClinicianName)
<br />
<br />
@Html.DisplayFor(modelItem => item.Location)
</div>
<div class="appointmentbutton appointmentbuttonclickable">
View @Html.ActionLink(" ", "Details", "MyAppointments", new { id = item.AppointmentIdentifier.id }, new { onclick = "getAppointmentRef( item.AppointmentIdentifier.id)" })
<br />
<img src="/Content/images/icons/view.png" alt="view icon" />
</div>
</div>
}
}
// jQuery - Very Basic for now also considered
$(".appointmentbutton").click(getAppointmentRef);
function getAppointmentRef(id) {
alert(id);
}
该函数调用正常,但即使我传递一个“你好”,它似乎也传递了一个 JSON 字符串,其参数都不是“id”,即 123456789
如何让 Actionlink 获取该模型项的 id?