我有一個foreach它給了我一個值串列,當單擊它時它會呼叫一個控制器:
@foreach (var item in Model)
{
<div>@Html.ActionLink(item.Text, "UpdateController",
new { subSectionID = item.Value, subsectionName = item.Text })</div>
}
我想這樣做,但現在使用下拉串列,單擊該值會將我重定向到控制器。
如果有人知道如何做或以其他方式做,也許在 html 中使用 Select,它會幫助我,謝謝!
uj5u.com熱心網友回復:
嘗試以下操作:
<script type="text/javascript">
$('#subsec').change(function () {
var url = $(this).val();
if (url != null && url != '') {
window.location.href = url;
}
});
</script>
@Html.DropDownListFor(m => Model.GetEnumerator().Current,
Model.Select(d =>
{
return new SelectListItem() {
Text = d.Text,
Value = Url.Action("Your_Action_Name", "Your_Controller_Name", new { subSectionID = d.Value, subsectionName = d.Text })
};
}),
"-Select a value-",
new { id = "subsec" })
您可以在此處找到類似的解決方案:https ://stackoverflow.com/a/6088047/6630084
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/485642.html
標籤:javascript html 网 asp.net-mvc
