Skip to content Skip to sidebar Skip to footer

Set Actionlink Routevalues Dynamically

I'm working on reading a value from textBox (let it be Sam): <%= Html.TextBox('Name')%> and then on click of action link: <%: Html.ActionLink('Edit','Edit',routeValues

Solution 1:

Since you aren't using any route values above and instead just the name of the textbox you can just create a link Name your textbox "name" (if it isn't already) via the html attributes new {id="name"} (for ex) then you can just jQuery to get the value and append it

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

You could also use the html help above and just attach an onclick event handler for jQuery as well.

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

something like that anyways off the top of my head.

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

Post a Comment for "Set Actionlink Routevalues Dynamically"