我需要在单击按钮时将文本框数据传递给 Controller 操作。这是我的代码:
<input id="txt" type="text">
<button onclick="@Url.Action("MyAction", "Mycontroller", new {currencyCode=ViewBag .currencyCode,endDate=Model.StartDate, value entered in txt above})" >
我不能在这里使用表格。您能否建议我如何访问/将此值传递给操作?
感谢您的帮助和指导。
最佳答案
下面的代码将文本框值发送到 Controller 的操作。
<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>
}
关于c# - 单击按钮时将文本框值传递给 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19580346/