与隐藏的文本框值一起使用的MVC4 ActionLink语法 [英] MVC4 ActionLink syntax for use with hidden text box values

查看:44
本文介绍了与隐藏的文本框值一起使用的MVC4 ActionLink语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将两个隐藏文本框中的两个值传递给控制器​​方法的秘密语法是什么?我尝试了以下语法,但得到了:CS0103:名称"SearchLatitude"在当前上下文错误消息中不存在.它看不到或不喜欢我名为SearchLatitude的隐藏文本框.不知道该怎么办,谢谢.

What is the secret syntax for passing in two values from two hidden text boxes to a controller method? I tried the syntax below but I get: CS0103: The name 'SearchLatitude' does not exist in the current context error message. It doesn't see or like my hidden text box named SearchLatitude. Not sure what to do, thank you.

@Html.ActionLink("SORT BY DISTANCE", "DisplayJobsDistance", "Job", new { Latitude = SearchLatitude, Longitude = SearchLongitude }, null)

<input type="hidden" name="SearchLatitude" id="SearchLatitude"> 
<input type="hidden" name="SearchLongitude" id="SearchLongitude"> 

推荐答案

您的ActionLink命令将不起作用,因为它正在名为 SearchLatitude 的视图中查找属性.您需要将此添加到传递给视图的模型中.如果您不知道这些值,也许是因为它们是在JavaScript中添加到客户端的,那么一些jQuery会有所帮助.

Your ActionLink command won't work because it's looking for a property in the view called SearchLatitude. You need to add this to the Model that is passed to the view. If you don't know these values, maybe because they're added in the client be JavaScript, then some jQuery will help.

@Html.ActionLink("SORT BY DISTANCE", "DisplayJobsDistance", "Job", null, new {id="sortlink"})

$("#sortlink").click(function()
{
    var $lat = $("#SearchLatitude").val();
    var $lon = $("#SearchLongitude").val();

    $(this).attr("href", $(this).attr("href") + "?latitude=" + $lat" + "&longitude=" + $lon);
}

这篇关于与隐藏的文本框值一起使用的MVC4 ActionLink语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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