display模版详细介绍
2015-02-27 16:20
281 查看
ASP.NET MVC 2 Templates, Part 4: Custom Object Templates
Series Index
Part 1: IntroductionPart 2: ModelMetadata
Part 3: Default Templates
Part 4: Custom Object Templates
Part 5: Master Page Templates
Customizing Templates
In Part 3, we saw what the default templates would look like if we’d written them as .ascx files. In this blog post, we’ll discuss some of the customizations you can make to the Object templates to enable different features and different displays for your template-based UI.For these examples, here are the models, controller, and views that we’ll be using.
Models/SampleModel.cs
?
?
?
?
?
The Default Display
When we show this home controller without any customizations, this is what the details page looks like:And this is our edit page:
Tabular Layout
One of the more commonly requested layouts is to do a tabular layout inside of the linear name/value, name/value layout that we do by default. Notice that the editor version of this layout also adds asterisks to the label for required fields.Views/Shared/DisplayTemplates/Object.ascx
?
Views/Shared/EditorTemplates/Object.ascx
?
Shallow Dive vs. Deep Dive
In the screenshots above, ChildModel is showing as “(null value)”. ChildModel is itself a complex model, so it follows the rules for shallow dive vs. deep dive. Before we have a child model object, it’s showing the NullDisplayText as we set in the attribute in the model above.Notice that even in edit mode above, we can’t edit the child model. That’s because the shallow dive logic prevents us from presenting a recursive editing UI.
If we change the Editor template above and remove the first “if” statement (which is what prevents the deep dive), then the editor will now show us editing fields for the child model:
And now our display shows:
Since we haven’t changed our Object Display template, we still get a shallow dive on this object. Further, it’s showing us the full name because we’ve used the DataAnnotations [DisplayColumn] attribute to say “display this property when showing this complex object in shallow form”. We’ve pointed [DisplayColumn] to a synthesized property called FullName, which we don’t normally show because we’ve annotated it with [ScaffoldColumn(false)].
If we change the Object Display template to do a deep dive, then we would see this:
Wrapping Up
In this blog post, I’ve shown you some of the ways you can customize the Object template to get different displays for your templates. That includes a tabular display instead of a linear display, adding asterisks to field names when fields are required, as well as enabling Deep Dive scenarios for complex objects inside of complex objects. In the next blog post, I’ll examine changing all the templates to enable an entirely different layout system centered around Master pages, inspired by Eric Hexter’s Opinionated Input Builders blog post series.文章引自:http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-4-custom-object-templates.html
相关文章推荐
- Django框架之模版(template)详细介绍
- 详细介绍弹性盒模型(display:flex)
- C++模版的详细介绍(学习笔记)
- 微信小程序 定义全局数据、函数复用、模版等详细介绍
- DDR和DDR2详细介绍
- SQL的详细语法介绍——对于学习数据库最基础知识[转]
- 计算机端口介绍[详细列表]
- GNU工程详细介绍by Richard Stallman
- SQL的详细语法介绍——对于学习数据库最基础知识一
- 什么是Perl?编程语言Perl详细介绍
- 常见的软件版本信息向大家做一详细的介绍(转)
- Raid磁盘阵列技术详细介绍
- 10款Linux下安全工具详细介绍
- 软件版本详细介绍
- (我整理的)OpenGL开发库的详细介绍
- 关于存储网络技术比较详细的介绍
- GNU工程详细介绍by Richard Stallman
- 40余种刻录盘片详细介绍
- FRIENDS演员详细介绍