0
私はデータがロードセットアップHTMLのdivクラスと設定のdivデータはカミソリビューにjqueryのを使用して属性
の属性セットアップクラスとhtmlにしようとしている<div class="child-station-sub child-station-sub1">
<h4><a href='#' class="child-station-opener station1 open" data-staion="NORTH_SOUTH_LINE">North - South Line</a></h4>
<div class="child-station-sub child-station-sub2">
<h4><a href='#' class="child-station-opener station2 subdrop" data-staion="EAST_WEST_LINE">East - West Line</a></h4>
<div class="child-station-sub child-station-sub3">
<h4><a href='#' class="child-station-opener station3 subdrop" data-staion="COST_WEST_LINE">Cost - West Line</a></h4>
以下のように私は、HTMLコードスニペットを持っています
は、だから私は、
@foreach (var item in ViewBag.listGroups)
{
<div id="divstation" class="child-station-sub child-station-sub1">
<p class="hidden">@item.ID</p>
<h4><a id="stationlg" href='#' class="child-station-opener station1 open" data-staion="EAST_WEST_LINE">@item.GroupName</a></h4>
}
<script type="text/javascript">
$(document).ready(function() {
var idvalue = item.ID.ToString();
if (idvalue == 1) {
alert('sample')
$('#divstation').attr('class', 'child-station-sub child-station-sub1');
$('#stationlg').attr('class', 'child-station-opener station1 open');
$('#stationlg').attr('data-staion', "NORTH_SOUTH_LINE");
}
else if (idvalue == 2) {
$('#divstation').attr('class', 'child-station-sub child-station-sub2');
$('#stationlg').attr('class', 'child-station-opener station2 subdrop');
$('#stationlg').attr('data-staion', "EAST_WEST_LINE");
});
else if (idvalue == 3) {
$('#divstation').attr('class', 'child-station-sub child-station-sub3');
$('#stationlg').attr('class', 'child-station-opener station3 subdrop');
$('#stationlg').attr('data-staion', "COST_WEST_LINE");
});
</script>
に従うが試みの上に正常に動作していないようにjQueryを使ってこれを実行しようとした私はここ
を何ができます3210
をレンダリングすることができますので、代わりにあなたは、ビューモデルを使用し、バックエンドから必要な
class
とdata-*
値などのすべてのそれらのデータを渡すことを検討すべきです無効なHTMLをレンダリングする__HTMLの識別子はユニークでなければなりません__ – Satpalこれは純粋なHTMLではありませんが、これは実際にはcshtmlです –
@kelumpriyadarshaneそれは依然として大きな要素ではない複数の要素に対して同じIDを作成します。 – Carcigenicate