我有一个input
和一个button
。输入值应该传递给@url.Action
,如下面代码中的描述:
<input class="in-class" id="textbox" type="text" runat="server" />
<button class="btn-class" id="press" type="button" onclick="location.href='@Url.Action("Index", "Home", new {id = /*Value Of textbox*/ })'" >click here</button>
正如我在代码中提到的,/*Value Of textbox*/
应该是输入的当前值。
发布于 2018-07-26 02:51:40
使用jQuery或JavaScript更改href值,如下所示:
<button class="btn-class" id="press" type="button" onclick="changeHref()" >click here</button>
function changeHref(){
var url = '@Url.Action("Index", "Home")';
var txtVal = $('#textbox').val();
window.location.href = url + '/?txtVal=' + txtVal;
}
发布于 2018-07-26 03:46:34
我使用这个表格
<input type="text" id="txtValue" /> <input type="button" value="Detail" onclick="location.href='@Url.Action("Action", "Home")?Value=' + $('#txtValue').val()" />
或者你不能在jquery函数中写这个。
https://stackoverflow.com/questions/51525632
复制相似问题