使用jquery变量作为.net MVC中ActionLink的参数
Using jquery variable as an argument for an ActionLink in .net MVC
只有我一个人,或者在javascript中处理变量真的很困难?
我的问题是,我想把javascript函数的一些结果用在MVC.net控制器中,但我做不到!
1.-我的JavaScript函数在一个视图上运行:
$(document).ready(function () {
$('#go').click(function () {
// test for presence of geolocation
if (navigator && navigator.geolocation) {
navigator.geolocation.getCurrentPosition(geo_success, geo_error);
} else {
// nothing at this moment.
function geo_success(position) {
printLatLong(position.coords.latitude, position.coords.longitude);
}
除了printLatLong函数外,我还想使用参数position.coord.latitude通过Html.ActionLink将其发送到控制器,如下所示:
@Html.ActionLink("Link to Controller", "Action", "Controller", position.coords.latitude)
但是我不能使用position.coords.latitude,因为现在我已经不能使用了。我只想在ActionLink中使用该值作为参数,这太难了吗?:(
提前感谢您的帮助。
只需使用html锚点并通过jquery操作href属性即可。
脚本:
function geo_success(position) {
printLatLong(position.coords.latitude, position.coords.longitude);
var url = '@Url.Action("Geo", "Home")';
// grab the anchor and modify the url
$("#geolink").attr("href", url += "?latitude=" + position.coords.latitude);
}
在您看来
<a id="geolink">GeoLink</a>
HomeController.cs
public ActionResult Geo(int latitude)
{
throw new Exception(String.Format("Do something with: {0}", latitude));
}
相关文章:
- 函数参数中的数据与指定变量之间的任何性能差异
- 使用Express捕获参数
- 参数变量出现ngTable指令问题
- AngularJS:我可以跳过函数参数回调吗
- 如何使用skip参数使用angular ui引导进行服务器端分页
- 要求未定义JS回调参数
- 我的jQuery插件参数没有正确启动,遇到了问题
- 获取@ResponseBody的一部分作为主干和Spring MVC控制器之间的参数
- jquery设置为使用参数运行
- Javascript”;类“;带有参数的扩展
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- Ajax.ActionLink-传递javascript参数
- 使用jquery变量作为.net MVC中ActionLink的参数
- 将选定的DDL值用作actionlink的参数
- C# asp.net MVC - 使用参数从 html.actionlink 调用脚本函数
- 从Javascript更改Actionlink参数
- 如何在@Html.ActionLink中的Querystring参数中传递String
- 从Ajax ActionLink MVC3.0传递参数到Javascript方法
- 是否有任何方法在MVC4 ActionLink中调用一个RouteValue参数
- 通过传递参数从html.actionlink调用JS