I plan to use some Model
properties to manage JavaScript code in HTML/Razor .
"columnDefs": [
{
"render": function (data, type, row) {
@if (Model.ConfigViewModel.AllowDeleteAnyUsers)
{
return '<center><img class="cursor-hand" onclick="javascript:ConfirmRemoveUser(this)" data-userId="' + row.Id + '" data-userName="' + row.UserName + '" src="images/delete.png" width="16" height="16" border="0"></center>'
}
else
{
return '<center><img class="cursor-hand" onclick="javascript:ConfirmRemoveUser(this)" data-userId="' + row.Id + '" data-userName="' + row.UserName + '" src="images/delete-disabled.png" width="16" height="16" border="0"></center>'
}
},
"targets": 3
}
But elements of JS code like row.Id
are giving errors like.
Compiler Error Message: CS1012: Too many characters in character literal
Any clue how to combine Razor and JS ?
Try to write it like this:
@if (Model.ConfigViewModel.AllowDeleteAnyUsers)
{
<text>
return '<center><img class="cursor-hand" onclick="javascript:ConfirmRemoveUser(this)" data-userId="' + row.Id + '" data-userName="' + row.UserName + '" src="images/delete.png" width="16" height="16" border="0"></center>';
</text>
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.