在剃刀code使用JavaScript变数 [英] Access Javascript variable in Razor code
问题描述
我想通过JavaScript变量,其中从剃刀页面调用C#方法。我想知道我该怎么做呢? (我是指这个链接但事与愿违为我工作。)
I want to pass javascript variable in the C# method which is call from the Razor page. May I know how can I do that? (I refer this link but it did not work for me.)
<script type="text/javascript">
function User(userID) {
var redirectUrl = '@Url.Action("AddEditUser", "User")';
window.location.href = redirectUrl + '/' + @SomeMethod("stringvalue",**userID**);
}
下面userID是JS对象,我想在我的服务器端方法传递。
我越来越喜欢类型或命名空间的定义,或预期的文件结束 - 和)预期的错误。
Here userID is JS object and I want to pass in my server side method. I am getting errors like "Type or namespace definition, or end-of-file expected" and ") expected".
编辑的文本:
我的加密code是在服务器端,我想和加密data.How一个AJAX请求我可以在AJAX请求发送加密的数据?
My encryption code is on server side and I want to make an AJAX request with encrypted data.How can I send an encrypted data in AJAX request?
推荐答案
您将需要做出一个Ajax调用和解决参数服务器端,或者创建客户端相当于你正在使用剃刀语法功能的。
寻找AJAX教程,如果你有它的经验,我听到jQuery是很不错的。
You will need to make an ajax call and resolve the parameter server side, or create a client side equivalent of the function you are using in razor syntax. Look for ajax tutorials if you have no experience with it, i hear jQuery is very good.
这篇关于在剃刀code使用JavaScript变数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!