什么是模型在ASP.NET MVC中绑定? [英] What is model binding in ASP.NET MVC?

查看:83
本文介绍了什么是模型在ASP.NET MVC中绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是模型,ASP.NET MVC结合,为什么需要什么?有人可以给简单的例子,可以模型绑定可以通过检查创建强类型的视图实现?

What is model binding in ASP.NET MVC, Why is it needed? Can someone give simple example , Can model binding be achieved by checking create strongly typed view?

推荐答案

ModelBinding 是ASP.NET MVC用来创建强类型对象的机制(或填充primitive-型参数)从输入流(通常是一个HTTP请求)。

ModelBinding is the mechanism ASP.NET MVC uses to create strongly-typed objects (or fill primitive-type parameters) from the input stream (usually an HTTP request).

例如,考虑这个模型:

public class Person
{
     public string Name { get; set; }
     public int Age { get; set; }
}

现在,你有一些动作在某些控制器这是期待类型作为参数:

Now, you have some Action in some Controller that's expecting a Person type as a parameter:

public class HomeController : Controller
{
      public ActionResult EditPersonDetails(Person person)
      {
          // ...
      }
}

模型文件夹然后负责填补参数为您服务。默认情况下,通过咨询 ValueProviders 收集,并要求在(受约束)模型中每个属性的值做的。

The Model-Binder is then responsible to fill that person parameter for you. By default it does it by consulting the ValueProviders collection and asking for the value of each property in the (to be bound) model.

更多关于价值提供商和模型粘合剂投放< href=\"http://haacked.com/archive/2011/06/30/whatrsquos-the-difference-between-a-value-provider-and-model-binder.aspx/\" rel=\"nofollow\">http://haacked.com/archive/2011/06/30/whatrsquos-the-difference-between-a-value-provider-and-model-binder.aspx/

More on Value-Providers and Model-Binders on http://haacked.com/archive/2011/06/30/whatrsquos-the-difference-between-a-value-provider-and-model-binder.aspx/

这篇关于什么是模型在ASP.NET MVC中绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆