一个partialLayout我有_PartialLayout页面如下获取模型属性的值从_layout
_PartialLayout.cshtml
@foreach (var item in ViewBag.listGroups)
{
string idvalue = item.ID.ToString();
switch (idvalue)
{
case "1":
<div class="gp-sub1">
<p class="hidden" id="gplineid">@item.ID</p>
<h4><a id="gpline" href='#' class="gp1 open" data-staion="GP_LINE">@item.GroupName</a></h4>
</div>
break;
}
...
}
这是_layout页
_Layout.cshtml
<!DOCTYPE html>
<html>
<head>
</head>
<body class="ss">
@Html.Partial("_PartialLayout")
</body>
</html>
<script type="text/javascript">
$(document).ready(function() {
$("#gpline").click(function() {
alert($('#gplineid').val());
});
});
</script>
在partilview布局一旦gpline
点击我试图让gplineid
如上,但这不提醒任何结果:(
与元素'ID =“gpline”'是没有价值的链接!你是什么意思_get gplineid_?你想要'@ item.ID'的价值吗? –
是的,我想得到'@ item.ID' – kez
然后,正如我以前告诉你的那样 - 在链接中添加'data-id =“@ item.ID”',然后使用alert $(this)来获取它。数据( '编号'));' –