I want to use a javascript variable in Razor like this :
my html:
@{List<AddTempViewModel> tempsToView = new List<AddTempViewModel>();
tempsToView = (List<AddTempViewModel>)ViewData["tempsToView"];}
@if (tempsToView != null)
{
@foreach (var item in tempsToView)
{
<a class="click" id="@item.TempDocumentId">
<img id="leftSideBarElement" src="@item.TempDocumentAddressUrl" />
</a><br />
}
<form method="post" action="">
<input id="documentNumber" class="form-control" type="text" name=""
placeholder="Email" />
</form>
and my script :
<script>
$(document).ready(function () {
$(".click").click(function () {
var divID = $(this).attr('id');
alert(divID);
var docName = @tempsToView[divID].TempDocumentId
$("#documentNumber").val(docName);
});
});
</script>
but I can't set the index of @tempsToView with divID. please help me what to do except this. thank you.