1

I am calling a EditDetails javascript function on click only if user has Admin permissions else disabling the button.

I see the error "Cannot implicitly convert type bool to string " at the javascript function name.

What may be the issue?

 <img src='../../Images/Edit.png' alt='Click to Edit' 
 onclick="@(Model.AdminPermissions ? "javascript:EditDetails('#@rowId');" ? "")" disabled="@(Model.AdminPermissions ? "" : "disabled")"

1 Answer 1

1

The error you were seeing is because you had accidentally included an extra ? inside of your @() block, and it should have been a :

enter image description here

Overall, it was close you just need to make sure that you break out of the string concatenation and get back to the razor (server) scope for the rowId.

<img src='../../Images/Edit.png' alt='Click to Edit' 
    onclick="@(
        Model.AdminPermissions ? "javascript:EditDetails('#" + rowId + "');" 
                               : ""
    )"
    disabled="@(Model.AdminPermissions ? "" : "disabled")
/>
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.