.net mvc ajax list post

http://stackoverflow.com/questions/13242414/passing-a-list-of-objects-into-an-mvc-controller-method-using-jquery-ajax

ajax 传递集合 给 mvc 的Action

$(document).ready(function () {
    var things = [
        { id: 1, color: ‘yellow‘ },
        { id: 2, color: ‘blue‘ },
        { id: 3, color: ‘red‘ }
    ];      

    things = JSON.stringify({ ‘things‘: things });

    $.ajax({
        contentType: ‘application/json; charset=utf-8‘,
        dataType: ‘json‘,
        type: ‘POST‘,
        url: ‘/Home/PassThings‘,
        data: things,
        success: function () {
            $(‘#result‘).html(‘"PassThings()" successfully called.‘);
        },
        failure: function (response) {
            $(‘#result‘).html(response);
        }
    });
});

public void PassThings(List<Thing> things)
{
    var t = things;
}

public class Thing
{
    public int Id { get; set; }
    public string Color { get; set; }
}
时间: 2024-08-03 20:32:04

.net mvc ajax list post的相关文章

MVC Ajax 提交是防止SCRF攻击

//在View中 <script type="text/javascript"> @functions{ public string ToKenHeaderValue() { string cookieToken,fromToken; AntiForgery.GetTokens(null,out cookieToken,out fromToken); return cookieToken+":"+fromToken; } } $function({ ..

MVC Ajax.BeginForm重复提交解决方法

mvc使用MVC Ajax.BeginForm提交的时候有重复提交结果的时候检查相关js文件引用情况, 其中mvc4注意 1 2 3 4 @Scripts.Render("~/bundles/modernizr") bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(                        "~/Scripts/jquery.unobtrusive*",

ASP.NET MVC ajax提交 防止CSRF攻击

//在View中 <script type="text/javascript"> @functions{ public string ToKenHeaderValue() { string cookieToken,fromToken; AntiForgery.GetTokens(null,out cookieToken,out fromToken); return cookieToken+":"+fromToken; }} $function({ ...

使用System.Web.Mvc.Ajax

摘自Rocky Ren 一.使用System.Web.Mvc.Ajax 1.1 System.Web.Mvc.Ajax.BeginForm 1.2 System.Web.Mvc.Ajax.ActionLink 二.手工打造自己的“非介入式”Javascript” 一.使用System.Web.Mvc.Ajax 1.1 System.Web.Mvc.Ajax.BeginForm 第一步:用Ajax.BeginForm创建Form 复制代码 @using (Ajax.BeginForm( new A

ASP.NET MVC AJAX调用JsonResult方法并返回自定义错误信息

一.如何用AJAX调用JsonResult方法 比如FuckController中添加有个返回JsonResult类型的方法FuckJson(): public JsonResult FuckJson() { return new JsonResult() { Data = new List<string>() { "fuck", "shit" }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }

MVC Ajax Form &amp; Ajax Valida(笔记)

1.引入必要的文件 <script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascri

asp.net mvc ajax.beginform()无法上传文件

Asp.Net Mvc使用Ajax.BeginForm上传文件Request.Files始终为null. 使用jquery.form.js插件能解决问题.asp.net mvc ajax.beginform()无法上传文件

MTV和MVC Ajax contentType 序列化组件 分页器

MTV与MVC模型        django框架 自称为是MTV框架            M:models            T:templates            V:views            MVC            M:models            V:views            C:controller 控制器(urls)        本质:MTV其实也是MVC Ajax    异步提交,局部刷新 请求方式      GET   POST a标签h

spring mvc+ajax 实现json格式数据传递

使用ajax传递JSON对象 下面示例为ajax发送json对象,返回json格式数据 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 $.ajax({ url: "api/user", type: "POST", timeout: txnTimeOut, async: true, dataType: "json", data: {username : "lucy"}

.net mvc Ajax.BeginForm 异步提交表单

Ajax.BeginForm异步表单用validform验证插件...... 之前找了一个jquery的验证插件validform,对此插件很满意,但是这个插件对<input type="button">按钮不感冒(检测不到这个按钮的onclick事件),只检测<input type="submit">的提交事件. 于是乎想到mvc 有一个异步表单Ajax.BeginForm,经测试可用.记录下来以便查阅 <script src=&qu