and then click ...">

Set Dynamic Route ActionLinkValues

I am working on reading a value from a textBox (let it be Sam):

<%= Html.TextBox("Name")%> 

and then click the action link:

 <%: Html.ActionLink("Edit","Edit",routeValues %> 

I need to route (this URL should open) / Edit / Sam

How can i do this?

0
source share
1 answer

Since you do not use any route values ​​above, but instead just the name of the text field, you can simply create a link. Name your text field "name" (if it is not already) through the html attributes new {id = "name"} (for ex) then you can just jQuery get the value and add it

  <a href="#" onclick="window.location.href='@Url.Action("Edit", "Edit")' + $('#name').val()"> Edit </a>

You can also use the html help above and just attach the onclick event handler for jQuery.

  $ (document) .ready (function () {
         $ ("# name"). click (function () {
             window.location.href = $ ('# idOfLinkHref'). attr ('href') + '/' + $ ('# name'). val ()
         });
     });

something like that anyway from the head.

There are many ways to do this - these are just a couple of ideas.

+1
source

All Articles