如何在ASP.NET MVC中将Textbox值发送到ActionLink [英] How to send Textbox value to ActionLink in asp.net mvc
本文介绍了如何在ASP.NET MVC中将Textbox值发送到ActionLink的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的情况
@Html.Textbox("value")
如何将上方的文本框值传递给下方的操作链接
how to pass above text box value to below action link
@Html.ActionLink("Search","Search",new {firstname=value)
推荐答案
您可以使用javascript来实现. 首先使用具有伪造的firstname值的href生成锚标记:
You can do it using javascript. First generate the anchor tag with a href having a faked value of firstname:
<a href="@Url.Action("Search", "Controller", new {firstname="xxxx"}") id="lnk">Search</a>
还要生成具有ID(即txtSearch)的.
Also, generate the with an ID (i.e. txtSearch).
然后,您可以使用javascript附加this的click事件.使用jQuery代码将类似于:
Then, using javascript you can attach the click event of this . Using jQuery code will be something like:
$("#lnk").click(function(evt) {
var fakedUri = $("#lnk").prop("href");
var uri = fakedUri.replace("xxxx", $("#txtSearch").val());
});
问候!
这篇关于如何在ASP.NET MVC中将Textbox值发送到ActionLink的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文