1

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?

1

1 Answer 1

1

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>
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.