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: ,
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>
Model Binding的更多相关文章
- [ASP.NET MVC 小牛之路]15 - Model Binding
Model Binding(模型绑定)是 MVC 框架根据 HTTP 请求数据创建 .NET 对象的一个过程.我们之前所有示例中传递给 Action 方法参数的对象都是在 Model Binding ...
- Asp.net MVC使用Model Binding解除Session, Cookie等依赖
上篇文章"Asp.net MVC使用Filter解除Session, Cookie等依赖"介绍了如何使用Filter来解除对于Session, Cookie的依赖.其实这个也可以通 ...
- [ASP.NET MVC] Model Binding With NameValueCollectionValueProvider
[ASP.NET MVC] Model Binding With NameValueCollectionValueProvider 范例下载 范例程序代码:点此下载 问题情景 一般Web网站,都是以H ...
- ASP.NET MVC3 Dynamically added form fields model binding
Adding new Item to a list of items, inline is a very nice feature you can provide to your user. Thi ...
- 【ASP.NET MVC 学习笔记】- 16 Model Binding(模型绑定)
本文参考:http://www.cnblogs.com/willick/p/3424188.html. 1.Model Binding是Http请求和Action方法之间的桥梁,是MVC框架根据Htt ...
- .NET Core开发日志——Model Binding
ASP.NET Core MVC中所提供的Model Binding功能简单但实用,其主要目的是将请求中包含的数据映射到action的方法参数中.这样就避免了开发者像在Web Forms时代那样需要从 ...
- 运用模型绑定和web窗体显示和检索数据(Retrieving and displaying data with model binding and web forms)
原文 http://www.asp.net/web-forms/overview/presenting-and-managing-data/model-binding/retrieving-data ...
- [置顶] ASP.NET MVC - Model Binding
Http Request 到Input Model的绑定按照model的类型可分为四种情况. Primitive type Collection of primitive type Complex t ...
- Model Binding To A List
[文章来源see here] Using the DefaultModelBinder in ASP.NET MVC, you can bind submitted form values to ar ...
- MVC3 Model Binding验证方式
1.使用ModelState在Action中进行验证 [HttpPost] public ViewResult MakeBooking(Appointment appt) { if (string.I ...
随机推荐
- P4行为模型BMV2依赖关系安装:thrift nanomsg nnpy安装
由于安装p4factory的步骤需要OF的支持,我需要下载p4的行为模型BMV2: thrift是支持BMV2的软件框架:nanomsg是一个实现了几种"可扩展协议"的高性能通信库 ...
- 使用Mongo官方驱动操作Mongo数据库
首先到 https://github.com/mongodb/mongo-csharp-driver/downloads 下载Mongo官方驱动 下载完成后引用到项目中 public class Co ...
- SqlServer判断表是否存在
.判断数据表是否存在 方法一: use yourdb; go if object_id(N'tablename',N'U') is not null print '存在' else print '不存 ...
- 探索.git目录
.git目录 下面就开始进入.git目录,通过“ls”命令可以看到.git目录中的文件和子目录: 对于这些文件和目录,下面给出了一些基本的描述. hooks:这个目录存放一些shell脚本,可以设置特 ...
- 微信公众平台开发(26) ACCESS TOKEN
本文介绍微信公众平台下Access Token的概念及获取方法. 一.Access Token access_token是公众号的全局唯一票据,公众号调用各接口时都需使用access_token.正常 ...
- MVC EF 执行SQL语句
最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷 学无止境,精益求精 闲着没事,看了一篇关于LINQ和SQL对比的文章,网友们 ...
- 解决编译错误: 非法字符: '\ufeff' 解决方案|错误: 需要class, interface或enum
http://www.cnblogs.com/oymx/p/5353235.html 可以 note++打开 在格式里 选择utf-8 无bom格式编码 即可
- AngularJS基础概要整理(下)
五.AngularJS Scope(作用域) Scope(作用域)是应用在HTML(视图)和JavaScript(控制器)之间的纽带. Scope是一个对象,有可用的方法和属性. Scope可应用在视 ...
- 简要介绍Apache、php、mysql安装和工具介绍
1 安装Apache 网站:www.Apache.org下载相应的Apache,目前下载了近期的:httpd-2.2.15-win32-x86-openssl-0.9.8msi 安装简要步骤如下图: ...
- 视觉中的深度学习方法CVPR 2012 Tutorial Deep Learning Methods for Vision
Deep Learning Methods for Vision CVPR 2012 Tutorial 9:00am-5:30pm, Sunday June 17th, Ballroom D (Fu ...