0

I'm trying to get the value of an asp.net variable to javascript. Firstly, i wanted to get the number of rows in my database using asp.net and entity framework. Here is the query:

getRowCountThmb = (from g in obj.thumbnailImages where g.instrumentItem.brand.name == stringInstrumentName && g.instrumentItem.model == stringInstrumentModel select g).Count();

And then, the retrieved row count will be passed on to the getRowCountThmb property which is like this(auto-implemented): public int getRowCountThmb { get; set; }. And after that, i will get the value of getRowCountThmb in javascript like this: var srcArray = "<%= getRowCountThmb %>";

The problem is, I have found out that the getRowCountThmb is not actually getting any row count in the database. The value is 0. Resulting to a NaN value in the javascript variable called scrArray. Kindly give advice or provide solutions for this.

2
  • A value of 0 should not cause a NaN. And not getting any rows has nothing to do with javascript. Commented Oct 3, 2017 at 13:57
  • as @VDWWD said, NaN shouldn't be caused by row count returning zero. Could you add your code to your question ? Commented Oct 3, 2017 at 14:02

1 Answer 1

1

This happens because you put getRowCountThmb in quotation marks when injecting it (whether its value is 0 or not does not matter), making srcArray a string. NaN stands for "Not a Number", which is correct in this case.

Essentially, what you end up having in your source code is:

var srcArray = "0"; // <-- This is not a number, but a string (NaN)

You can solve this by removing the quotes like so:

var srcArray = <%= getRowCountThmb %>;
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.