我的观看代码是
<tr bgcolor="#FFFFFF">
<td height="36" align="right" bgcolor="#F7F7F7"><strong>System</strong> </td>
<td height="36">
@Html.DropDownListFor(model => model.CSNumber, new SelectList(ViewBag.System, "Value", "Text", Model.CSNumber), "--- All ---", new { @class = "box", id = "ddlSystem" })
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="36" align="right" bgcolor="#F7F7F7"></td>
<td height="36">
System = @Html.Value(**"ddlSystem"**)
<a class="" href="~/jobs/Create?system=<<Currently Selected Value of **"ddlSystem"** up above>>" id="createLink" style="text-decoration: underline">NEW REQUEST</a>
</td>
</tr>
当用户点击CREATE NEW REQUEST LINK时,如何传递当前选定的ddlSystem下拉值?
答案 0 :(得分:0)
我使用jQuery,就像这样:
$(function () {
$("#createLink").click(function () {
var selectedValue = $('#ddlSystem option:selected').val();
window.location = "@Url.Action("Create", "Jobs")?system=" + selectedValue;
});
});
答案 1 :(得分:0)
您可以编写 JQuery ,如下所示,它实际上设置了链接的“href”属性。这样,当用户改变下拉值时,“href”将被更新。
<script>
$(document).ready(function () {
function setBtnUrl() {
$('#createLink').attr('href', '/jobs/Create?system=' + $("#ddlSystem").val());// here it update the URL based on selected value
}
$("#ddlSystem").change(function () {
setBtnUrl();
});
setBtnUrl();// set the selected value on page load.
});
</script>