Uncaught SyntaxError: missing ) after argument list

QuestionsCategory: Asp.netUncaught SyntaxError: missing ) after argument list
Harry Dew asked 4 years ago

Hi,
In my ASP.NET MVC application View, I’m getting this error in my browser console

Uncaught SyntaxError: missing ) after argument list

here’s my code for passing parameters to JavaScript function

<a href="javascript:EditUser( @item.id , @item.name );">Edit</a>

and this is for receiving Parameters

<script>
    function EditUser(id, name) {
       
       alert(name);
    }
</script>

 

 

Disclosure of Material Connection: Some of the links in the post above are “affiliate links.” This means if you click on the link and purchase the item, we will receive an affiliate commission. Regardless, we only recommend products or services we use personally and believe will add value to our readers.

1 Answers
Best Answer
Shehryar Khan Staff answered 4 years ago

just add single quotes with parameters and change this line

<a href="javascript:EditUser( @item.id , @item.name );">Edit</a>

to this

<a href="javascript:EditUser( '@item.id' , '@item.name' );">Edit</a>

 

Disclosure of Material Connection: Some of the links in the post above are “affiliate links.” This means if you click on the link and purchase the item, we will receive an affiliate commission. Regardless, we only recommend products or services we use personally and believe will add value to our readers.