私はmvc4/razorを使用しています。VS 2012では、上下のボタンを使用してmvcリストボックス内のアイテムを上下に移動しようとしています。これらは listorder/index.cshtml 内の私のコントロールです スクリプトを試しましたが、ここでは機能しません。助けてください
@{
var Resource = new List<SelectListItem> {
new SelectListItem { Text = "res1", Value = "1"},
new SelectListItem { Text = "res2", Value = "2" },
new SelectListItem { Text = "res3", Value = "3" },
new SelectListItem { Text = "res4", Value = "4" }
};
}
@Html.ListBox("ListReorder", Resource, new { @class = "ListMain"})
<input type="button" value="Up" id="ResUpButton" onclick="MoveUp()" /> <br />
<input type="button" value="Down" id="ResDownButton" onclick="MoveDown()" />
<script src="scripts/jquery-1[1].3.2.js" type="text/javascript"></script>
<script type="text/javascript">
function MoveDown() {
var selectedOption = $('#ListReorder > option[selected]');
var nextOption = $('#ListReorder > option[selected]').next("option");
if ($(nextOption).text() != "") {
$(selectedOption).remove();
$(nextOption).after($(selectedOption));
}
}
function MoveUp() {
var selectedOption = $('#ListReorder > option[selected]');
var prevOption = $('#ListReorder > option[selected]').prev("option");
if ($(prevOption).text() != "") {
$(selectedOption).remove();
$(prevOption).before($(selectedOption));
}
}
</script>