如何将IEnumerable列表从Ajax发送到Controller [英] How to send IEnumerable list from Ajax to Controller

查看:169
本文介绍了如何将IEnumerable列表从Ajax发送到Controller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MVC3中有一个Web应用程序,并且正在使用Telerik网格批处理编辑.

I have a web application in MVC3 and i'm using Telerik Grid Batch Editing.

批处理编辑具有保存更改"按钮,该按钮会将UPDATED COLUMNS返回到控制器IEnumerable列表,例如

Batch Editing have save changes button which returns UPDATED COLUMNS to controller IEnumerable list like

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

但是如何收集更新的行并使数组像IEnumerable list这样从Java脚本中用Ajax发送到Controller?

but how to collect updated rows and make array send like IEnumerable list from Javascript with ajax to Controller ?

编辑 我将视图设为png

EDIT I'm putting my view png

我只想将更新的行数据发送到Controller,保存更改"按钮可以做到这一点,但是在发送值之前,我只想问用户您确定要加载吗?"在发送数据之后,我想刷新所有页面

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?" and after the send data I want to refresh all the page

所以我想对ajax请求执行此操作,因为我也对ajax请求使用批处理编辑

So i thinked to do this with ajax request because i'm also using batch editing with ajax requests

您对此情况有经验吗?

推荐答案

使用AJAX POST,就像我在经过测试的Javascript"函数中使用的那样::

Use the AJAX POST as I have used in my Tested Javascript function as::

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");
        }
    });
}

然后在服务器端(即在Controller中)使用类似以下内容的内容:

And on Server Side(i.e. In Controller) use something Like::

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

ViewModel包含不同的属性,这些属性具有不同的数据类型,例如::

The ViewModel Contains different propeties which are of different datatypes as::

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

这很好.可能会对您有帮助.

This is working fine. May be this will help you.

这篇关于如何将IEnumerable列表从Ajax发送到Controller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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