Tou*_*ubi 1 c# asp.net-mvc asp.net-mvc-4
我需要在按钮单击时将文本框数据传递给控制器操作.这是我的代码:
<input id="txt" type="text">
<button onclick="@Url.Action("MyAction", "Mycontroller", new {currencyCode=ViewBag .currencyCode,endDate=Model.StartDate, value entered in txt above})" >
Run Code Online (Sandbox Code Playgroud)
我不能在这里使用表格.你能告诉我如何访问/传递这个值吗?
感谢您的帮助并指导我.
下面的代码将文本框值发送到控制器的操作.
<input id="txt" type="text">
<button id="button">Click Me</button>
@section Scripts {
<script type="text/javascript">
$("#button").click(function () {
var txtVal = $("#txt").val();
window.location = "@Url.Action("TheAction","TheController")" +
"/" + txtVal;
});
</script>
}
Run Code Online (Sandbox Code Playgroud)