问题
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 %>
I need to route (this URL should open) /Edit/Sam
How can I do that?
回答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.
来源:https://stackoverflow.com/questions/5837851/set-actionlink-routevalues-dynamically