简体   繁体   中英

Calling C# code method with parameters in javascript using razor

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM