asp.net - ActionLink routeValue from a TextBox -


i'm working on following:

1- user enters value inside textbox.

2- clicks edit go edit view.

this code:

   <%=   html.textbox("name") %>      <%: html.actionlink("edit", "edit")%>  

the problem can't figure out how take value textbox , pass actionlink, can me?

you can't unless use javascript. better way achieve use form instead of actionlink:

<% using (html.beginform("edit", "somecontroller")) { %>     <%= html.textbox("name") %>     <input type="submit" value="edit" /> <% } %> 

which automatically send value entered user in textbox controller action:

[httppost] public actionresult edit(string name) {     ... } 

and if wanted use actionlink here's how setup javascript function send value:

<%= html.textbox("name") %> <%= html.actionlink("edit", "edit", null, new { id = "edit" })%>  

and then:

$(function() {     $('#edit').click(function() {         var name = $('#name').val();         this.href = this.href + '?name=' + encodeuricomponent(name);     }); }); 

Comments