Uncaught SyntaxError: missing ) after argument list

QuestionsCategory: Asp.netUncaught SyntaxError: missing ) after argument list
Harry Dew asked 2 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>

 

Recommended Training – Treehouse

TreehouseFrom beginner to advanced, our recommended coding training is Treehouse.

Treehouse is an online training service that teaches web design, web development and app development with videos, quizzes and interactive coding exercises.

Treehouse's mission is to bring technology education to those who can't get it, and is committed to helping its students find jobs. If you're looking to turn coding into your career, you should consider Treehouse.

 

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 2 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>

Recommended Training – Treehouse

TreehouseFrom beginner to advanced, our recommended coding training is Treehouse.

Treehouse is an online training service that teaches web design, web development and app development with videos, quizzes and interactive coding exercises.

Treehouse's mission is to bring technology education to those who can't get it, and is committed to helping its students find jobs. If you're looking to turn coding into your career, you should consider Treehouse.

 

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.