Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8492399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:42:27+00:00 2026-06-10T22:42:27+00:00

When calling a javascript function, it only works if I pass in an int.

  • 0

When calling a javascript function, it only works if I pass in an int. It fails if I pass in a string.

For example, this is my controller where I’m passing in a list of people to the view.

public ActionResult Index()
{
    List<Person> people = new List<Person>();
    people.Add(new Person() { Id = 1, FirstName = "Geddy", LastName = "Lee" });
    people.Add(new Person() { Id = 2, FirstName = "Alex", LastName = "Lifeson" });

    return View(people);
}

In the view, I have this javascript function:

function RemovePerson(firstName) {
    alert(firstName);
}

My webgrid has a column that allows the user to delete a person:

gridPeople.Column(header: "", columnName: "",
    format: (person) => MvcHtmlString.Create(string.Format(
    "<a href='' onclick='RemovePerson({0}); return false;'>x</a>",
    person.FirstName))),      

As the code is shown, above, I get this error when I click the x to delete a person:

Uncaught Reference Error: Geddy is not defined

Why?

If I change the javascript to accept an int:

function RemovePerson(personId) {
    alert(personId);
}

And actually pass the int:

gridPeople.Column(header: "", columnName: "",
    format: (person) => MvcHtmlString.Create(string.Format(
    "<a href='' onclick='RemovePerson({0}); return false;'>x</a>",
    person.Id))), 

It correctly shows a message box with the int value. So why does this work when passing an int but not the name?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:42:29+00:00Added an answer on June 10, 2026 at 10:42 pm

    The reason is that you need to wrap the string variable in quotes.

    Uncaught Reference Error: Geddy is not defined

    That means it thinks you’re referring to a variable named Geddy rather than the string literal "Geddy".

    Here’s what you use:

    string.Format("<a href='' onclick='RemovePerson(\"{0}\"); return false;'>x</a>",
    person.Id)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is related to a question I've asked previously: Calling Javascript function after loading
Possible Duplicate: calling ASP function from javascript okay running this code : <script type=text/javascript>
I am calling a Javascript function in my html page from a Flash movie
Here i am calling a javascript function on a button click and i need
I'm calling the JavaScript function onsubmit of form but form has submit before finished
I have a javascript function for checking errors which I am calling on OnClicentClick
I'm calling a utility called Highslide in a javascript function. Embedding the whole thing
I have a javascript file which has a function calling a server (url) to
On load I'm both calling a JavaScript setTimeout() function that will hide a .NET
I'm writing this bookmarklet in Javascript, which is also calling some JQuery objects. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.