How to send text field value to ActionLink in asp.net mvc

Here is my script

@Html.Textbox("value") 

how to pass above the value of the text field below the action link

 @Html.ActionLink("Search","Search",new {firstname=value) 
+6
source share
2 answers

You can do this with javascript. First create an anchor tag with href having a fake firstname value:

 <a href="@Url.Action("Search", "Controller", new {firstname="xxxx"}") id="lnk">Search</a> 

Also, generate an identifier (i.e. txtSearch).

Then, using javascript, you can attach the click event of this. Using jQuery code will look something like this:

 $("#lnk").click(function(evt) { var fakedUri = $("#lnk").prop("href"); var uri = fakedUri.replace("xxxx", $("#txtSearch").val()); }); 

Hello!

+12
source

You need to use a form

 <form method="post" action="@Url.Action("Search", "Search")"> @Html.Textbox("value") </form> 
+1
source

Source: https://habr.com/ru/post/944618/


All Articles