易截截图软件、单文件、免安装、纯绿色、仅160KB

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&


相关文档:

asp.net 程序动态添加gridview

前台:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
   
   
     ......

Asp.net 中 Cookie的使用方法

方法1:
比如建立一个名为cnlive,值为"123"的cookie
HttpCookie cookie = new HttpCookie["cnlive"];
cookie.Value = "123";
Response.AppendCookie(cookie);
取刚才写入的Cookie值:
HttpCookie cookie = Request.Cookies["cnlive"];
cookieValue = cookie.Value;
在一个Cookie中储存多个信息:
HttpCookie cookie ......

关于asp.net的配置文件

配置文件可用来存放一些多次用到的常量数据,如连接串:
<appSettings>
<add key="connStr1" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="/>
<add key="connStr2" value="App_Data\test.mdb"/>
</appSettings>
这个配置数据库连接串
使用示例:
  public class DBCo ......

asp.net用户ASPNET登录失败的问题

 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
  异常详细信息: System.Data.SqlClient.SqlException: 用户 'XXXASPNET' 登录失败。
  今天将网站迁移过来后,就发现这个问题.经过摸索,发现原因是我们登录数据库的角色对数据库的权限不够. ......

学习asp.net C#

 1、DateTime   数字型  
System.DateTime   currentTime=new   System.DateTime();  
  1.1   取当前年月日时分秒  
currentTime=System.DateTime.Now;  
  1.2   取当前年  
int   年=currentTime.Year;  
  1.3   取当前月 &n ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号