How to post an array of complex objects with JSON, jQuery to ASP.NET MVC Controller?

問題:

My current code looks like the following. 我當前的代碼如下所示。 How can I pass my array to the controller and what kind of parameters must my controller action accept? 如何將我的數組傳遞給控制器​​以及控制器操作必須接受哪種參數?

function getplaceholders() {
    var placeholders = $('.ui-sortable');
    var result = new Array();
    placeholders.each(function() {
        var ph = $(this).attr('id');
        var sections = $(this).find('.sort');
        var section;

        sections.each(function(i, item) {
            var sid = $(item).attr('id');

            result.push({ 'SectionId': sid, 'Placeholder': ph, 'Position': i });
        });
    });
    alert(result.toString());
    $.post(
        '/portal/Designer.mvc/SaveOrUpdate',
        result,
        function(data) {
            alert(data.Result);
        }, "json");
};

My controller action method looks like 我的控制器動作方法看起來像

public JsonResult SaveOrUpdate(IList<PageDesignWidget> widgets)

解決方案:

參考: https://stackoom.com/en/question/1LJz
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章