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 ...
随机推荐
- SHARE NOTHING SHARE EVERYTHING
http://mp.weixin.qq.com/s?__biz=MjM5ODYwMjI2MA==&mid=2649736156&idx=1&sn=23931f48282f6ef ...
- Synergy 鼠标和键盘共享软件
http://symless.com/nightly Synergy 正可以让你的多台电脑共享一套键鼠,甚至还可以共享剪贴板,如同一机多屏,并跨平台支持 .
- The Python Tutorial
1. >>> print('C:\some\name') # here \n means newline! C:\some ame >>> print(r'C:\s ...
- How to prevent SQL injection attacks?
In our earlier tutorial on SQL Injection, one way to have prevented the SQL injection attack was by ...
- MVC项目中验证码的使用
这是我记录验证的第二篇文章,之前还有一篇是ashx一般处理程序的. 验证码类: 需要添加两个引用:System.Web.System.Drawing //需要添加两个引用:System.Web.Sys ...
- Struts2(四):在Action中如何访问Web资源
1.什么WEB资源? HttpServletRequest,HttpServletRespone,HttpApplication,ServletContext,HttpSession等原生Servle ...
- 【Selenium】1.介绍 Selenium
本文供学习交流之用,没有商业用途,没有盈利. 完全是我自己为督促自己学习而翻译的.翻译的不好,见谅.来源于:http://www.guru99.com/introduction-to-selenium ...
- 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数009,Measure,测量函数
<zw版·Halcon-delphi系列原创教程> Halcon分类函数009,Measure,测量函数 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替 ...
- uber 真是垃圾
uber司机好几次都不认识路,态度也不好,最开始使用是因为它价格最便宜,随着滴滴/快的价格下调,已经没有再使用uber的必要,果断卸载.
- PythonPP+lambda:示例
直接上代码. python PP 下载, 可以到官网下载 Python PP 下载 lambda 能做的, 基本上普通函数都可以做到. lambda 的主要作用是简化表达式, 并且似乎尤其适合于表达科 ...