Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc jquery可排序,获取列表顺序_Asp.net Mvc_Jquery Ui - Fatal编程技术网

Asp.net mvc jquery可排序,获取列表顺序

Asp.net mvc jquery可排序,获取列表顺序,asp.net-mvc,jquery-ui,Asp.net Mvc,Jquery Ui,在使用jquery进行排序时,是否有任何方法返回列表中某个对象的排名?本质上,我想做成千上万其他人正在做的事情(我已经彻底搜索了stackoverflow),并从一个可排序的数据库更新数据库 数据库中的每个项都有一个“位置”属性-最初设置为0。ul被填充和绘制,我想在更新时路由回控制器,并将其位置存储在列表中 我正在使用ASP.NET MVC/C作为我的代码库,但我很难找到这方面的完整示例。哈!我想出来了。我把它贴在这里供大家欣赏 $("ul#unorderedListIdGoesHere li

在使用jquery进行排序时,是否有任何方法返回列表中某个对象的排名?本质上,我想做成千上万其他人正在做的事情(我已经彻底搜索了stackoverflow),并从一个可排序的数据库更新数据库

数据库中的每个项都有一个“位置”属性-最初设置为0。ul被填充和绘制,我想在更新时路由回控制器,并将其位置存储在列表中


我正在使用ASP.NET MVC/C作为我的代码库,但我很难找到这方面的完整示例。

哈!我想出来了。我把它贴在这里供大家欣赏

$("ul#unorderedListIdGoesHere li").index(ui.item);


<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Models.Section>>" %>

    <ul id="sections">
    <% foreach (var item in Model) { %>
    <li class="ui-state-default" id="<%= item.Id %>">
        <span class="ui-icon ui-icon-arrowthick-2-n-s"></span><%= Html.Encode(item.Name) %>
    </li>
    <% } %>
    </ul>

<script type="text/javascript">
    $(document).ready(function() {
    $("#sections").sortable({
    update: function(event, ui) {
            $("ul#sections li").each(function(){
                var position = $("ul#sections li").index(this);
                var section = $(this).attr("id");
                $.post("/Sections/Position", { position: position, section: section });
                })
            }
        }).disableSelection();
    });
</script>
<style type="text/css">
    #sections { list-style-type: none; margin: 0; padding: 0; width: 60%; }
    #sections li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.4em; height: 18px; }
    #sections li span { position: absolute; margin-left: -1.3em; }
</style>
$(“ul#unorderedlistidgoesher li”).索引(ui.item);
$(文档).ready(函数(){ $(“#节”)。可排序({ 更新:功能(事件、用户界面){ $(“ul#li”)。每个(函数(){ var头寸=$(“ul#li”)。指数(本); var section=$(this.attr(“id”); $.post(“/Sections/Position”,{Position:Position,section:section}); }) } }).disableSelection(); }); #节{列表样式类型:无;边距:0;填充:0;宽度:60%;} #部分li{空白:0 3px 3px 3px;填充:0.4em;左填充:1.5em;字体大小:1.4em;高度:18px;} #第li节span{位置:绝对;左边距:-1.3em;}
哈哈!我想出来了。我把它贴在这里供大家欣赏

$("ul#unorderedListIdGoesHere li").index(ui.item);


<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Models.Section>>" %>

    <ul id="sections">
    <% foreach (var item in Model) { %>
    <li class="ui-state-default" id="<%= item.Id %>">
        <span class="ui-icon ui-icon-arrowthick-2-n-s"></span><%= Html.Encode(item.Name) %>
    </li>
    <% } %>
    </ul>

<script type="text/javascript">
    $(document).ready(function() {
    $("#sections").sortable({
    update: function(event, ui) {
            $("ul#sections li").each(function(){
                var position = $("ul#sections li").index(this);
                var section = $(this).attr("id");
                $.post("/Sections/Position", { position: position, section: section });
                })
            }
        }).disableSelection();
    });
</script>
<style type="text/css">
    #sections { list-style-type: none; margin: 0; padding: 0; width: 60%; }
    #sections li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.4em; height: 18px; }
    #sections li span { position: absolute; margin-left: -1.3em; }
</style>
$(“ul#unorderedlistidgoesher li”).索引(ui.item);
$(文档).ready(函数(){ $(“#节”)。可排序({ 更新:功能(事件、用户界面){ $(“ul#li”)。每个(函数(){ var头寸=$(“ul#li”)。指数(本); var section=$(this.attr(“id”); $.post(“/Sections/Position”,{Position:Position,section:section}); }) } }).disableSelection(); }); #节{列表样式类型:无;边距:0;填充:0;宽度:60%;} #部分li{空白:0 3px 3px 3px;填充:0.4em;左填充:1.5em;字体大小:1.4em;高度:18px;} #第li节span{位置:绝对;左边距:-1.3em;}
你能回答吗?你能回答吗?