如果您想从下拉列表中选择任何值,请执行任何操作,请尝试以下操作:
HTML:
<select onchange = "redirect(this.value)" class="required" data-val="true" id="DownloadValuesId" name="DownloadValuesId">
<option value="">option1</option>
<option value="2">option2</option>
<option value="3">option3</option>
<option value="4">option4</option>
<option value="5">option5</option>
</select>
和 javascript:
<script type="text/javascript">
function redirect(dropDownValue) {
window.location.href = '@Url.Action("Action", "Controller")/' + '?id=' + dropDownValue;
}
</script>
编辑:
使用按钮发送值onclick="AnyFunction()"
并获取任何隐藏元素。首先,为该隐藏元素提供下拉值,然后使用 onclick 将其发送到操作:
<a id="download" onclick="SendValue()" target="_blank">Download</a>
和js:
<script type="text/javascript">
function redirect(dropDownValue) {
document.getElementById('hiddenElement').value = dropDownValue;
}
function SendValue() {
window.location.href = '@Url.Action("Action", "Controller")/' + '?id=' + document.getElementById('hiddenElement').value;
}
</script>
您也可以使用 jquery 执行此操作:
$.ajax({
type: "POST", //or GET
url: "@Url.Action("Action", "Controller")",
data: "{ id : 'anyValue', serviceId : 'Any value' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
//do something
}
});