[英]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. 我试图在我的javascript代码中调用C#方法,并尝试使用razor语法将参数传递给它,但无法正确执行。 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. 编译器错误消息:CS0103:当前上下文中不存在名称“cellvalue”。
Can someone tell me the correct syntax of how to pass parameter in above? 有人能告诉我如何在上面传递参数的正确语法吗?
C# runs server-side. C#运行服务器端。 The
@
code is running server-side before the script is delivered to the client and has no access to the JavaScript values. 在脚本交付给客户端之前,
@
code正在运行服务器端,并且无法访问JavaScript值。
Your JavaScript runs client-side and has no ability to call server-side methods. 您的JavaScript在客户端运行,无法调用服务器端方法。
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. 如果要向客户端公开服务器端功能,则必须使用AJAX并为客户端提供一些服务来调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.