将.NET AJAX转换为MVC /学习-是否可以在不破坏MVC范例的情况下实现此功能?

问题描述

| 我正在尝试在MVC中复制以下功能,我已经将其用于AJAX: 用户一个项目拖放到页面上。 OnDropped会创建一个新控件并将其附加到页面上。该控件是RadDock类型的控件,它将停靠在RadDockZone类型的控件中。 旧代码
    /// <summary>
    /// Creates the RadDock + Contents when dropping a graph onto the page.
    /// </summary>
    /// <param name=\"sender\"> The RadListBox with an element being dropped from inside it. </param>
    /// <param name=\"e\"> information about the drop such as target and what is being dropped. </param>
    protected void RadListBox_Dropped(object sender,RadListBoxDroppedEventArgs e)
    {
        CormanTradDockZone dockZone = RadDockLayout1.RegisteredZones.OfType<CormanTradDockZone>().First(registeredDockZone => registeredDockZone.ID == e.HtmlElementID);

        if (!object.Equals(dockZone,null) && !dockZone.Docks.Any())
        {
            RadSlidingPane slidingPane = ((sender as RadListBox).Parent as RadSlidingPane);
            CormantReport report = new CormantReport(int.Parse(e.sourceDragItems[0].Value),e.sourceDragItems[0].Text,slidingPane.Title);
            CormanTradDock dock = new CormanTradDock(report);
            dock.CreateContent();
            dock.Dock(dockZone);
        }
    }
现在,我一直在努力思考如何在MVC中执行类似的操作。我认为应该发生的是,视图应获取必要的数据,然后将该数据传递回控制器。控制器将处理创建RadDock的操作,然后将对象转换为JSON并将数据传递回视图。检索完数据后,我相信我可以以某种方式重新创建元素,以便可以将其附加到RadDockZone,但没有Telerik.Web.UI.RadDock()构造函数...似乎完全没有希望? 这可能吗?
function OnClientDropped(sender,eventArgs) {
//Capture e.HTMLElementID,e.sourceDragItems[0].Value,and slidingPane.Title here

var droppedID = eventArgs.get_htmlElement().id;

if( droppedID.indexOf(\"RadDockZone\") != -1 )
{
    var radDockZone = $find(droppedID);
    //This constructor does not exist!
    var radDock = new Telerik.Web.UI.RadDock();
    radDock.dock(radDockZone);
}
else
{
    alert(\"Failed to find RadDockZone on dropped target.\");
}

var slidingPaneTitle = \"\";

if (sender.get_id().indexOf(\"lstBxHistorical\") != -1) {
    slidingPaneTitle = \"Historical Widgets\";
}
else if (sender.get_id().indexOf(\"lstBxCustom\") != -1) {
    slidingPaneTitle = \"Custom Widgets\";
}
else {
    alert(sender.get_id());
}

$.ajax({
    type: \'POST\',url: \'ReportDropped\',dataType: \'json\',data: {
        //e.HTMLElementID,etc...
    },success: function (data) {

        alert(\"Success\");
    },errror: function (xhr,ajaxOptions,error) {
        alert(\"Error\");
    }
});
}     

解决方法

           我有它为AJAX工作: 我相信您的意思是aps.net ajax。而且,不能将asp.net的服务器控件与mvc一起使用,因为mvc根本没有任何ASP.net服务器控件严重依赖的ViewState概念。如果您确实想使用这样的控件,则有两个选择(我能想到) 实现与asp.net mvc兼容的自己的控件 或者并排运行asp.net和mvc并在需要的地方使用asp.net服务器控件