使用 Url.action() 传递动态 javascript 值 [英] Passing dynamic javascript values using Url.action()

查看:34
本文介绍了使用 Url.action() 传递动态 javascript 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我如何使用 Url.action() 传递动态值.

Could anyone please tell how to pass dynamic values using Url.action().

类似的东西,

var firstname="abc";
var username = "abcd";
location.href = '@Html.Raw(@Url.Action("Display", "Customer", new { uname = firstname ,name = username}))';

名字,用户名不会在 Url.action() 方法中被引用.

firstname, username is not getting reffered inside the Url.action() method.

如何使用 Url.action() 传递这些动态值?

How to pass these dynamic values using Url.action()?

推荐答案

@Url.Action() 方法是服务器端的过程,所以你不能将 client-side 值作为参数传递给该函数.您可以将 client-side 变量与此方法生成的 server-side url 连接起来,这是输出中的一个字符串.尝试这样的事情:

The @Url.Action() method is proccess on the server-side, so you cannot pass a client-side value to this function as a parameter. You can concat the client-side variables with the server-side url generated by this method, which is a string on the output. Try something like this:

var firstname = "abc";
var username = "abcd";
location.href = '@Url.Action("Display", "Customer")?uname=' + firstname + '&name=' + username;

@Url.Action("Display", "Customer")server-side 上处理,字符串的其余部分在 上处理>client-side,将 server-side 方法的结果与 client-side 连接起来.

The @Url.Action("Display", "Customer") is processed on the server-side and the rest of the string is processed on the client-side, concatenating the result of the server-side method with the client-side.

这篇关于使用 Url.action() 传递动态 javascript 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆