【发布时间】:2009-04-08 14:21:19
【问题描述】:
在 DTO 对象中,我想对呈现的 html 文本框的标签描述进行硬编码,这样我就可以拥有一个像 TextBoxWithLabel 这样的 html 辅助函数,其中我只传递对象,它会自动创建从描述中获取的标签属性。
public class MessageDTO
{
public int id { get; set; }
[Description("Insert the title")]
public string Title { get; set; }
[Description("Description")]
public string Body { get; set; }
}
然后在我的视图页面中我想调用:
<%=Html.TextBoxWithLabel<string>(dto.Title)%>
并在渲染视图中获取
<label for="Title">Insert the title :</label>
<input id="Title" type="text" value="" name="Title"/>
我认为要实现这一点,我应该使用反射。是正确的还是会减慢视图渲染速度?
【问题讨论】:
标签: asp.net asp.net-mvc reflection attributes