zoukankan      html  css  js  c++  java
  • Model Binding

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    
    namespace MvcApplication1.Controllers
    {
        public class Person
        {
            public string Name { get; set; }
            public int Age { get; set; }
            //public List<KeyPair> Numbers { get; set; }
            public object Numbers { get; set; }
        }
    
        public class KeyPair
        {
            public string Key { get; set; }
            public string Value { get; set; }
        }
    
        public class HomeController : Controller
        {
            //
            // GET: /Home/
    
            public ActionResult Index()
            {
                return View();
            }
    
            public void Post(Person data)
            {
                var numbers= data.Numbers as List<KeyPair>;
            }
    
        }
    }
    @{
        ViewBag.Title = "Index";
    }
    <button id="btn">TEST</button>
    <h2>Index</h2>
    <script src="~/Scripts/jquery-2.0.3.js"></script>
    <script>
        var data = {
            Name: "tom",
            Age: 10,
            Numbers: [{ Key: "a", Value: "A" }, { Key: "b", Value: "B" }]
        };
        $(function() {
            $("#btn").on("click", function() {
                $.ajax({
                    url: "/Home/Post",
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    data:JSON.stringify(data),
                    dataType: "Json"
                });
            });
        });
    </script>
  • 相关阅读:
    【模板】高斯消元
    【洛谷P1730】最小密度路径
    【模板】矩阵乘法优化线性递推
    【洛谷P3723】礼物
    【洛谷P3338】力
    【模板】NTT
    【洛谷P1919】A*B Problem升级版
    测试理论基础(思维导图)
    Fiddler
    常用 Linux 命令
  • 原文地址:https://www.cnblogs.com/shineqiujuan/p/3281756.html
Copyright © 2011-2022 走看看