2

I am trying to call a C# method in my javascript code and also trying to pass parameter to it using razor syntax but not able to do it correctly. Below is my code:

function RecallNoFmatter(cellvalue) {
    var value = @(Precall.S300FormatRecall(+cellvalue+));
    return value;

}

I get this error message:

Compiler Error Message: CS0103: The name 'cellvalue' does not exist in the current context.

Can someone tell me the correct syntax of how to pass parameter in above?

2
  • What in the world is +cellvalue+ supposed to mean? Commented Feb 27, 2013 at 15:55
  • 1
    Based on your earlier question, you are grossly misunderstanding server vs client side code and what the relationship between them is. You should take a step back and try to understand those two concepts, and then these things will seem much simpler and more obvious. Commented Feb 27, 2013 at 16:01

1 Answer 1

6

C# runs server-side. The @ code is running server-side before the script is delivered to the client and has no access to the JavaScript values.

Your JavaScript runs client-side and has no ability to call server-side methods.

If you want to expose server-side functionality to the client, you're going to have to use AJAX and provide some service for the client to call.

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.