Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send Textbox value to ActionLink in asp.net mvc

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)
like image 741
Muralikrishna Avatar asked May 09 '13 10:05

Muralikrishna


Video Answer


2 Answers

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!

like image 90
eiximenis Avatar answered Sep 23 '22 17:09

eiximenis


You need to use a form

<form method="post" action="@Url.Action("Search", "Search")">
     @Html.Textbox("value")
</form>
like image 20
roryok Avatar answered Sep 22 '22 17:09

roryok