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 ...
随机推荐
- python 正则使用笔记
python正则使用笔记 def remove_br(content): """去除两边换行符""" content = content.r ...
- 怎样成为全栈工程师(Full Stack Developer)?
"Facebook 工程师说 Facebook 只招 full stack engineer,那么 Facebook engineer 都是怎样的人啦."? 具体经验不重要,重要的 ...
- AjaxPost、冒泡示例
//Ajax提交表单 $("#AssetsForm").submit(function () { $.ajax({ type: "post", url: &qu ...
- iOS小技巧3
将颜色合成图片 将颜色合成图片 +(UIImage *)imageWithColor:(UIColor *)color { CGRect rect = CGRectMake(0.0f, 0.0f, 1 ...
- ios - 文件保存路径的获取
"应用程序包": 这里面存放的是应用程序的源文件,包括资源文件和可执行文件. 获取方式: NSString *path = [[NSBundle mainBundle] bundl ...
- Lua Rings库介绍
Rings需求 如果有一段lua脚本代码, 本来来源不可靠, 可能有安全性问题, 或者不像让这份代码污染了正在执行的lua环境, 则需要lua rings工具出厂了. 其在主lua环境中,即在宿主脚本 ...
- Cross-site Scripting (XSS) 阅读笔记
本文源自 https://www.owasp.org/index.php/Cross-site_Scripting_%28XSS%29 通过阅读和翻译,并按照自己的理解,整理成如下文档. 概述 XSS ...
- RDIFramework.NET V2.8版本 ━ 开发实例之产品管理(WinForm)
RDIFramework.NET V2.8版本 ━ 开发实例之产品管理(WinForm) 现在,我们使用.NET快速开发整合框架(RDIFramework.NET)来开发一个应用,此应用皆在说明如何使 ...
- input内强制保留小数点后两位 位数不足时自动补0
input内强制保留小数点后两位 位数不足时自动补0 小数点后位数超出2位时进行四舍五入 需引入jquery包 1.11.2版本 1 function xiaoshu(x) 2 { 3 var f = ...
- Centos7中源码安装Nodejs
Step 1.确认服务器有nodejs编译及依赖相关软件,如果没有可通过运行以下命令安装. [root@BobServerStation local]# yum -y install gcc gcc- ...