ASP。净MVC模型元数据(一)

  

,

ASP。净MVC模型元数据(一)

,

<强>元模型数据 <李>

<李>

<李>

<李>

<李>

<李>

<李>

,

,,,,,,public  class 客户   ,,,{   ,,,,,,,public  string  CustomerID {组,得到,,,}   ,,,,,,,public  string  Name {组,得到,,,}   ,,,,,,,public  DateTime  RegistrationDate{组,得到,,,}   ,,,,,,,public  Address  Address {组,得到,,,}   ,,,,,,,   ,,,}   ,,,public  class 地址   ,,,{   ,,,,,,,public  string  Name {组,得到,,,}   ,,,}

1,,,,,,,,,public  ViewResult 显示(Customer 客户)   2,,,,,,,,,{   3,,,,,,,,,,,,,return 视图(客户);   4,,,,,,,,,}

然后我们右键显示()方法,添加视图,并且勾选创建强类型视图,如图1所示。

图1 - 1

 ASP。净MVC模型元数据(一)

& lt; p> @Html.EditorForModel () & lt;/p>

using  System.Web.Mvc;   using  ConsoleApplication2;   namespace  MvcApplication.Binders   {   ,,,public  class  MyCustomBinderModel: IModelBinder   ,,,{   ,,,,,,,public  object  BindModel (ControllerContext  controllerContext, ModelBindingContext  bindingContext)   ,,,,,,,{   ,,,,,,,,,,,return  new 客户()   ,,,,,,,,,,,{   ,,,,,,,,,,,,,,,CustomerID =,“010”,   ,,,,,,,,,,,,,,,Name =,“测试人员”,   ,,,,,,,,,,,,,,,RegistrationDate =, DateTime.Now,   ,,,,,,,,,,,,,,,Address =, new 地址()   ,,,,,,,,,,,,,,,{   ,,,,,,,,,,,,,,,,,,,Name =,“天空之城”   ,,,,,,,,,,,,,,,}   ,,,,,,,,,,,};   ,,,,,,,}   ,,,}   }

ModelBinders.Binders.Add (typeof(客户),new  Binders.MyCustomBinderModel ());

这个时候我们来调试一下,结果如图1 - 2。

图1 - 2

 ASP。净MVC模型元数据(一)

图1 - 3

,

ASP。净MVC模型元数据(一)