set ActionLink routeValues dynamically

六眼飞鱼酱① 提交于 2019-12-12 02:24:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!