我需要将 txtRemarks 和 txtCost 文本框值放入 Button OnClick 方法的两个参数中。这样我就可以将这些参数传递给 Controller 中的方法。让我进一步解释一下。我有两个在模型外创建的文本框。下面我已经提到了它们。
@Html.Editor("txtRemarks", new { htmlAttributes = new { @class = "form-control date-picker", @placeholder = "N/A" } })
@Html.Editor("txtCost", new { htmlAttributes = new { @class = "form-control date-picker", @type = "number", @placeholder = "0.00" } })
我需要在 Button Onclick 事件中将它们的值传递给两个参数。下面是点击事件和按钮。我需要将这些参数值获取到 Controller ServiceHeaders
中的 ActionResult 方法 ServiceDetails<input type="button" id="btnAddtoGrid" value="Add" class="btn btn-group" onclick="location.href='@Url.Action("ServiceDetails", "ServiceHeaders")?Remark='+ $('#txtRemarks').val(),?Cost='+ $('#txtCost').val()" />
我只需要一种方法来连接 ?Remark='+ $('#txtRemarks').val()
和 ?Cost='+ $('#txtCost'). val()
。我可以使用 ?Remark='+ $('#txtRemarks').val()
或 ?Cost='+ $('#txtCost').val() 传递一个参数
。但我不知道如何同时获得两者。这就是我需要您宝贵帮助的地方。
最佳答案
您可以链接参数,例如:
localhost?Remark='+ $('#txtRemarks').val() + '&Cost='+ $('#txtCost').val()
.
在执行 HTTP GET 时,您可以使用 ...?var1=test1&var2=test2&var3=test3
等设置参数
参见 doc了解更多信息。
注意:您也可以考虑为您的案例使用 HTTP POST。
关于javascript - 如何将文本框值获取到 Button OnClick 函数中的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56020857/