A razor block containing a JavaScript function

When a user clicks on the button, I am attempting to call an EditDetails JavaScript function only if the user has Admin permissions. Otherwise, the button is disabled.

However, there seems to be an error message stating "Cannot implicitly convert type bool to string" related to the name of the JavaScript function.

What might be causing this issue?

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

Answer №1

The issue that caused the error is due to the accidental inclusion of an extra ? inside your @() block, when it was supposed to be a :

In essence, you were very close to the correct solution but you just needed to remember to exit out of the string concatenation and return to the razor (server) scope for the variable rowId.

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Experiencing difficulties with file paths for images in a project utilizing tailwind CSS and React

I've run into an issue with setting a url path in JavaScript to use with a variable, specifically when it comes to the path for my image. Oddly enough, the src attribute path is generating empty images, while paths used inside tailwind and similar fr ...

Ways to modify the pre-defined value in a TextField

I encountered a situation where I have a form with pre-filled data from a specific country. The data is initially read-only, but the user can click on the edit button if they wish to make changes. The issue arises when trying to edit the value in the Text ...

Encountered a Puppeteer Protocol issue: Error occurred when attempting to call a function on a closed

Exploring the world of JavaScript and nodejs as a beginner. Attempting to create a PDF table with node.js through Google puppeteer. Referenced a tutorial for the code below, all credit goes to the original source. Using a sample HTML template to populat ...

It seems that the Bootstrap 4 Modal Pop up window is having difficulty closing

I recently completed a project on creating a matching game. After all the cards are successfully matched and the game finishes, a congratulatory modal pops up. However, I encountered an issue where the modal would not close after clicking the "Play Again" ...

What steps can be taken to make the carousel inconsistent when relying on the assigned id in props?

I recently developed a slider with slots, but encountered an issue. The code for this component revolves around the use of IDs for each slide as prop, making it unnecessarily complex. I am convinced that there is a more straightforward way to achieve the s ...

What is the best way to access the data transferred by a $.ajax function in my PHP script?

An error is popping up on the .php page stating: Notice: Undefined index: name $.ajax({ url: 'test.php', type: "GET", data: ({name: "James"}), success: function(data){ console.log(data); } }); The goal is to retrieve th ...

Using jQuery to add a class to an input option if its value exists in an array

Looking for a way to dynamically add a class to select option values by comparing them with an array received from an ajax call. HTML <select id="my_id"> <option value="1">1</option> <option value="2">2</option> ...

I am interested in redirecting command line output to a file rather than displaying it in the standard

Is it possible to use child-process and spawn in node.js to execute a command and save the output to a file instead of displaying it on the standard output? test.js const expect = require('chai').expect; const { spawn } = require('child_pr ...

"Can you provide guidance on binding data in vue.js when there is a dash (-) in the key of the JSON

My JSON data is structured as follows: { "color-1": "#8888", "color-2": "#000" } I am attempting to bind this variable with a style tag for a Vue component. However, my current approach seems to not be functioning as expected. <div v-bind:sty ...

What could be the reason for the warnings I'm receiving regarding type assignment in Typescript version 5?

I have a function that I regularly use to combine two objects of the same type: export function mergeObjects<T>(currentObject: T, updatedObject: Partial<T>): T { const newObject: T = structuredClone(currentObject); if (!updatedObject) retur ...

Using JSON.parse to convert a JSON list into a JavaScript array is not functioning correctly

By utilizing this function, I am able to fetch a JSON list: $(document).ready(function () { var idContact = @ViewData["IdPhysique"]; var Url = "/Accueil/DonneListeFonctionContact"; $.getJSON(Url, { IdContact: idContact }, function ...

Guide on assigning a material to ColladaLoader or OBJLoader

I've searched extensively through the documentation and numerous examples, but I couldn't find the correct syntax for assigning a material to either a Collada .dae or OBJLoader .obj file. Json files seem to work well when creating a Mesh, with t ...

What could be the reason for the Mootools Multibox images displaying scrollbars when initially viewed?

We have implemented the Mootools Multibox plugin to showcase our images. Upon the initial viewing in Chrome and Safari, we noticed that the images are zoomed in and display with scrollbars. However, upon refreshing the page, the images render correctly wi ...

Unlocking Fields in SharePoint 2007: A Step-by-Step Guide to Enabling a Disabled Field with Checkbox Activation

Hey there! I'm curious to find out what I might be overlooking... function executeMe(){ if(document.getElementById("ctl00_m_g_ef941f4a_7f2d_4a75_a119_6f009e7a22ad_ctl00_ctl04_ctl04_ctl00_ctl00_ctl04_ctl00_ctl00").checked{ document.getElementById("c ...

Activate the button for a single user exclusively on the webpage

I'm working on a project where I need to control several rotating devices with the push of a button. The catch is, I only want one user to be able to activate the button at a time. Essentially, when a user accesses the website, I need to determine if ...

Creating a seamless navigation experience using Material UI's react Button and react-router-dom Link

Is there a way to have the Material UI react Button component behave like a Link component from react-router-dom while preserving its original style? Essentially, how can I change the route on click? import Button from '@material-ui/core/Button' ...

React not functioning properly when packaged with Webpack

I tried implementing React in the simplest way possible, but I am facing some issues. After bundling React and opening the index.html page, it shows up completely blank with no console errors to indicate any mistakes. Below is my webpack.config.js: const ...

There seems to be an issue with sending multiple parameters correctly in the get method when using Angular 5 with a Node.js backend

I have been working on creating an API with nodejs and trying to access it using the GET method by sending parameters through Angular 5 GET method. While testing the API with Postman, everything works fine, but when I try to send the GET request from Angul ...

What is the method for obtaining a date in the format of 2018-05-23T23:00:00.000+00:00?

Recently, I've been attempting to filter data based on dates in my database. The format in which the dates are saved is as follows: 2018-05-23T23:00:00.000+00:00 This was my initial approach: router.get('/byDate', function (req, res) { ...

Exploring Angular component testing through jasmine/karma and utilizing the spyOn method

I have been facing an issue while trying to test my component. Even though the component itself works perfectly, the test keeps generating error messages that I am unable to resolve. Here is the snippet of code that I am attempting to test: export cl ...