惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
NISL@THU
NISL@THU
E
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
K
Kaspersky official blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
S
Schneier on Security
G
GRAHAM CLULEY
The Hacker News
The Hacker News
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
爱范儿
爱范儿
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
S
Securelist
G
Google Developers Blog
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
美团技术团队
F
Fortinet All Blogs
小众软件
小众软件
Recorded Future
Recorded Future
V
Visual Studio Blog
B
Blog RSS Feed
H
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
Latest news
Latest news
Spread Privacy
Spread Privacy
H
Heimdal Security Blog

博客园 - ∈鱼杆

TraceView .NET WAP网站开发系列 ASP.NET RSS开发札记(完结) MonoRail MVC实践应用(完结) HowTo:String.Format新方法 HowTo:C#性能测试扩展函数 Python性能测试工具 Excel分类汇总宏(VBA) Python性能测试工具 HowTo:C#性能测试扩展函数 面向方面的编程在Cache、Log、Trace方面的运用 MonoRail MVC应用(2)-构建多层结构的应用程序 MonoRail MVC应用(1)-VM/HTML页面 MonoRail MVC实践应用 W3WP进程CPU查看 innerHTML和P标签 [转] 有关敏捷的若干思考 .NET WAP开发及兼容问题 ASP.NET分页控件(AspNetPager分页控件)
MonoRailMVC应用-母板页的Title
∈鱼杆 · 2008-12-22 · via 博客园 - ∈鱼杆

母板页是具体设计网站首先要面对的问题。MonoRail默认在Views/layouts目录中。因为我配置过目录,所以我的目录是在wap3/layouts下。接下来我沿用ASP.NET对母板页的一些说法来表述,方便大家更快的理解和使用
内容页中设置母板页的Title、Metal信息
因为MonoRail的layouts是没有后代码的(重点说明),那么有些需要在母板页处理的逻辑怎么使用呢?其实很简单只要在母板页上定义一个变量,内容页进行赋值即可
母板页添加如下代码:

 <title>$headtitle </title>

内容页CS代码进行赋值

public void Index()
{
   PropertyBag["HeadTitle"] = "首页数据";
}

这样就完成了在内容页中修改母板页内容的过程。
母板页的默认值
但这样你会发现一个,就是每一个调用母板页的地方都必须去设置这个headtitle,否则他直接输出$headtitle。显然需要一个默认值。每一个页面去设置默认值,加重了开发的负担。这样我就定义了一个BaseController类
public class BaseController : Controller
{
public BaseController()
{
PropertyBag["HeadTitle"] = String.Empty;
}
}

让所有的内容页后代码都从BaseController继承,这样就解决的默认值的问题
空默认值更简单
你如果认为新定义一个基类比较麻烦,而你的值默认是为空的,那么这样使用更加方便。如果没有赋值,在内容页中将不显示

 <title>$!headtitle </title>

但如果你需要一些定制化的默认值,这样就比较麻烦了。所以我还是建议都从BaseController继承。