保存JQuery的可排序(新订单),以ASP.Net MVC控制器? [英] Saving JQuery Sortable (new order) to ASP.Net MVC controller?

查看:113
本文介绍了保存JQuery的可排序(新订单),以ASP.Net MVC控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现JQuery的排序,并能正常工作。问题是我不能在新秩序通过列表控制器,所以我可以保存它。

I've implemented JQuery sortable, and it works fine. The problem is I can't pass the list in its new order to a controller so i can save it.

<script type="text/javascript">  
    $(document).ready(function() {  
        $("#sortable").sortable({ axis: "y" });  
    });  

    $(function() {  
        $("#submit-list").button();  

        $("#submit-list").click(function() {  
            debugger;  
            $.ajax({  
                url: '/Admin/SortedLists/',  
                data: { items: $("#sortable").sortable('toArray') },  
                type: 'post',  
                traditional: true  
            });  
        });  

    });  
</script>    

<h2>Edit Roles</h2>  

<div>  
    <ul id="sortable">  
        <% foreach (var item in Model.Roles) { %>                  
            <li>                  
                <%=Html.AttributeEncode(item.Name)%>                              
            </li>                                                                               
        <% } %>             
    </ul>  

    <input type="submit" value="Save" id="submit-list"/>  
</div>  

和我的控制器:

[HttpPost]  
    public EmptyResult SortedLists(List<string> items)  
    {  
        return new EmptyResult();  
    }  

列表项回来与元素的数量corrent - 除了每个项目都是空字符串。

List items comes back with the corrent number of elements - except each item are empty strings.

如果原来的列表看起来像这样

If the original list looks like this


  1. 1 - 汽车

  2. 2 - 船

  3. 3 - 摩托车

  4. 4 - 平面

和用户拖动和度假村为


  1. 4 - 平面

  2. 1 - 汽车

  3. 3 - 摩托车

  4. 2 - 船

我如何传递这个新秩序?我想ID传递提交整个事情,删除整个列表并重新提交此整个列表

How can i pass that new order? I suppose id pass the whole thing on submit, delete the entire list and resubmit this whole list

除非那里有更好的办法?趁着LINQ的(使用LINQ to SQL),我可以在everychange插入新秩序,并做了提交更改的?

unless theres a better way? Taking advantage of Linq (using Linq to SQL) where i can insert the new order on everychange and do a submit changes?

推荐答案

我所要做的就是在id字段填写每个列表项的 的toArray 方法后返回的列表精细

All I had to do was fill in the id field for each list item, toArray method returned the list fine after that

<ul id="sortable">  
    <% foreach (var item in Model.Roles) { %>                  
        <li id="<%=Html.AttributeEncode(item.Name)%>"><%=Html.AttributeEncode(item.Name)%></li>                                                                                    
    <% } %>             
</ul>  

这篇关于保存JQuery的可排序(新订单),以ASP.Net MVC控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆