简体   繁体   English

如何将IEnumerable列表从Ajax发送到Controller

[英]How to send IEnumerable list from Ajax to Controller

I have a web application in MVC3 and i'm using Telerik Grid Batch Editing. 我在MVC3中有一个Web应用程序,我正在使用Telerik Grid Batch Editing。

Batch Editing have save changes button which returns UPDATED COLUMNS to controller IEnumerable list like 批量编辑有保存更改按钮,它将UPDATED COLUMNS返回到控制器IEnumerable列表中

    [GridAction]
    public ActionResult Update(IEnumerable<Customers> updated)
    {
        ///user codes
    }

but how to collect updated rows and make array send like IEnumerable list from Javascript with ajax to Controller ? 但如何收集更新的行,并使用ajax到控制器的数组发送像Javascript的IEnumerable列表?

EDIT I'm putting my view png 编辑我正在把我的观点png

在此输入图像描述

I just want to send updated rows data to Controller and Save Changes button can do this but before thje send values i just want to ask to user "Are you sure to Load?" 我只想将更新的行数据发送到Controller并保存更改按钮可以执行此操作但在发送值之前我只想向用户询问“你确定要加载吗?” and after the send data I want to refresh all the page 并且在发送数据之后我想刷新所有页面

So i thinked to do this with ajax request because i'm also using batch editing with ajax requests 所以我想用ajax请求这样做,因为我也使用批量编辑与ajax请求

Do you have any exprience for this situation? 你对这种情况有什么看法吗?

Use the AJAX POST as I have used in my Tested Javascript function as:: 使用我在测试的Javascript函数中使用的AJAX POST ::

function TestAjax() {
    var Test = [];

    for (var i = 0; i < 5; i++) {
        Test.push({ ID: i, Name: "RJ" });
    }

    $.ajax({
        type: 'POST',
        url: rootUrl('Home/TestPost'),
        contentType: "application/json",
        //data: { Test: JSON.stringify( data) },
        data:JSON.stringify( {Test: Test}),
        success: function (data) {
            alert("Succeded");
        }
    });
}

And on Server Side(ie In Controller) use something Like:: 在服务器端(即在控制器中)使用类似::

public ActionResult TestPost(IEnumerable<TestViewModel> Test)
    {
        return Json(3);
    }

The ViewModel Contains different propeties which are of different datatypes as:: ViewModel包含不同数据类型的不同属性::

public class TestViewModel
    {
        public long ID { get; set; }
        public string Name { get; set; }
    }

This is working fine. 这工作正常。 May be this will help you. 可能这会对你有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM