How to send Textbox value to ActionLink in asp.net

2020-07-13 08:17发布

Here is my scenario

@Html.Textbox("value")

how to pass above text box value to below action link

@Html.ActionLink("Search","Search",new {firstname=value)

2条回答
SAY GOODBYE
2楼-- · 2020-07-13 08:28

You need to use a form

<form method="post" action="@Url.Action("Search", "Search")">
     @Html.Textbox("value")
</form>
查看更多
时光不老,我们不散
3楼-- · 2020-07-13 08:42

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>

Also, generate the with an ID (i.e. txtSearch).

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());
});

Greetings!

查看更多
登录 后发表回答