Javascript 在Jquery onDrop之后,如何通过Ajax获取PartialView的ActionResult并将其附加到Div中

Javascript 在Jquery onDrop之后,如何通过Ajax获取PartialView的ActionResult并将其附加到Div中,javascript,ajax,asp.net-mvc,drag-and-drop,Javascript,Ajax,Asp.net Mvc,Drag And Drop,在一页中,我有 缩略图/IMG列表,以及用户可以在其中拖放这些文档缩略图的位置 在OnDrop()事件之后:如何使用列表项的id触发/male对ASP MVC操作方法的Ajax调用 然后将来自partialview/View的ReturnActionResult作为嵌套div附加到容器中 <div id="container"></div> $("#containere").droppable({ accept: "#contain

在一页中,我有

缩略图/IMG列表,以及用户可以在其中拖放这些文档缩略图的位置

OnDrop()
事件之后:如何使用列表项的
id
触发/male对ASP MVC操作方法的Ajax调用

然后将来自partialview/View的ReturnActionResult作为嵌套div附加到容器中

<div id="container"></div> 

    $("#containere").droppable({ 
        accept: "#container",
        drop: function( event, ui ) {
            //how to make the ajax call with item id?
        } 
});

我应该在这里使用Html.Partial还是Partial View?

ui参数包含有关拖动的元素的信息,因此您可以使用

$("#containere").droppable({ 
    accept: "#container",
    drop: function( event, ui ) {
        var id = ui.draggable.data('index-number'); // returns 'picture1' if the 1st li element is dragged/dropped
        // or var id = ui.draggable.attr('id'); if you want the 'pic1' value
        $.ajax({
            type: "GET",
            url: '@Url.Action("GetMyPartialView", "Home")', // don't hard code url's
            data: { ThumNailId: id },
            ....
        });     
    } 
});
注意,这假设您的方法是signature is

public ActionResult GetMyPartialView(string ThumNailId)

你是如何给你的
  • 元素一个“id”的?@StephenMuecke我已经编辑了列表来显示id的。另外,在Id上使用HTML5数据val属性是否更好,请建议哪一个最好作为唯一的Id发送谢谢,我可以标记为答案(yes getpartalview sig是正确的),一个问题是,这是否适用于返回,或者是否会卡在http响应流
    $(“#容器”).html(myresult.ViewString)//我从控制器返回的HTML
    。您还使用了数据值data-
    索引编号
    覆盖列表id,这样更好吗。感谢使用
    data-
    属性更好(
    id
    属性用于标识css和javascript选择器使用的DOM中的元素)。如果您的方法返回一个局部视图,它将正常工作-但您似乎没有这样做(您似乎返回一个包含属性
    Status
    ViewString
    的对象,原因不明-为什么不返回一个局部视图或
    null
    ,然后您可以使用
    success:function(response){If(response){$(“#Container”).html(response)}其他{showPopup(…);}
    )感谢您的解释:)将尝试
    ActionResult
    和您的建议,
    成功:函数(response){if(response){$(“#Container”).html(response)}
    -1)这也适用于任何html,比如如果我返回图表。我发现它会在同一个div中转储所有附件,2)如何将每个返回的pic附加到新的
    文档中。createElement('div'))
    现在BS3的所有内容都在同一个div中,我想给它们单独的div。3)是否可以对它们进行排序,还是应该将其放在主
    容器div
    @转换器上,如果没有更多的信息,很难知道您想要做什么,以及希望生成的html是什么样子。我不知道我甚至不知道你从这个方法返回的html是什么。我建议你问一个更详细的新问题。
    public ActionResult GetMyPartialView(string ThumNailId)