ASP.NET MVC 2 模版系列2: ModelMetadata
同样是一篇转帖的文章,
原文: http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-2-modelmetadata.html
着重介绍了ASP.NET MVC2 里面的 ModelMetadata 类
ASP.NET MVC 2 Templates, Part 2: ModelMetadata
Series Index
Part 1: Introduction
Part 2: ModelMetadata
Understanding Your Model
One
of the classes we introduced with ASP.NET MVC 2 is ModelMetadata. This
class is designed to tell you interesting things about the objects you
want to display or edit. While we commonly use them when writing
templates, this metadata is actually always available, even when you’re
not in a template.
What is a Model?
When it comes to ModelMetadata, the definition of “model” is probably a bit blurrier than you’re used to.
Let’s say for instance that you have the model from part 1 of this blog series:
view sourceprint?
1.public class Contact {
2. public string FirstName { get; set; }
3. public string LastName { get; set; }
4. public int Age { get; set; }
5.}
You created a strongly-typed view for this model, and if inside the
view you access ViewData.ModelMetadata, then the model at this point is
the Contact object.
However, through this metadata object, you can also get metadata
about all of its properties. This returns a collection of ModelMetadata
objects, one for each of the properties. If we were to do this with our
Contact object, we’d end up with 3 new metadata objects, one each for
FirstName, LastName, and Age. When you’re looking at the model metadata
for FirstName, the model type is String (and the container type is
Contact). In this way, you can even recursively dive through several
layers of complex objects via properties.
How Do I Get One?
Use the one for the current model.
The most common way to get one is to access the
ModelMetadata property on ViewData as shown above. This metadata object
describes the ViewData&
相关文档:
1.
此处提供的代码用来实现当asp.net
页面中的某个Button
被点击后disable
掉该页面中所有的Button
,从而防止提交延时导致的多次提交。基于之前的onceclickbutton
脚本.
//ASP.NET
中防止页面多次提交的代码:javascript< script
language="javascript"> < !-- function dis ......
一. 使用QueryString变量
QueryString是一种非常简单也是使用比较多的一种传值方式,但是它将传递的值显示在浏览器的地址栏中,如果是传递一个或多个安全性要求不高或是结构简单的数值时,可以使用这个方法。
Response.Redirect( "target.aspx?param1=hello& ......
1 response.redirect 这个跳转页面的方法跳转的速度不快,因为它要走2个来回(2次postback),但他可以跳 转到任何页面,没有站点页面限制(即可以由雅虎跳到新浪),同时不能跳过登录保护。但速度慢是其最大缺陷!redirect跳转机制:首先是发送一个http请求到客户端,通知需要跳转到新页面,然后客户端在发送跳转 ......
适用于:microsoft ASP.NET
摘要:asp.net动态生成html页面,适用
简介
此功能适用于后台数据库功能不强的web站点,即大部分文本不是存放在数据库的记录中,而是放在html文件或者xml文件中,仅仅把索引放到数据库中,如文章标题、类别、查询关键字等。这样适合于后台没有诸如ms Sql Server这样的数据库支持的Web站点。
适 ......
Eval( " ")和Bind( " ") 这两种一个单向绑定,一个双向绑定
bind是双向绑定,但需数据源可更改才能用
ASP.NET 2.0改善了模板中的数据绑定操作,把v1.x中的数据绑定语法DataBinder.Eval(Container.DataItem, fieldname)简化为Eval(fieldname)。Eval方法与DataBinder.Eval一样可以接受一个可选的格式化字符串参数。缩短的Ev ......