高级 Razor : Templated Razor Delegate
来源:互联网 发布:ubuntu wireshark lua 编辑:程序博客网 时间:2024/05/29 18:54
1. 使用 Razor 模板委托 是 Fun<T,HelperResult> 类型,在模板中( Func<dynamic, object> strongTemplate =@<strong>@item</strong>;
)@item 是个神奇的参数,尽管这些委托只能有这样的参数,但是模板可以多次引用。
<div> @{ Func<dynamic, object> strongTemplate =@<strong>@item</strong>; } <p>Advance Razor(Templated Razor Delegate) By zhou44129879</p> @strongTemplate("This is bolded.")</div>
2. 我们可以扩展 WebPageBase 类中的 RenderSection 方法来使用Fun<T,HelperResult> 类型.
public static class RazorLayoutHelpers {public static HelperResult RenderSection(this WebPageBase webPage,string name,Func<dynamic, HelperResult> defaultContents) {if (webPage.IsSectionDefined(name)) {return webPage.RenderSection(name);}return defaultContents(null);}}
调用:
<footer>@this.RenderSection("Footer", @<span>This is the default.</span>)</footer>
扩展发放是.net 3.5的新特性,不懂得可以自己网上看下(this WebPageBase webPage)。
- 高级 Razor : Templated Razor Delegate
- 【MVC】@helper 语法/Templated Razor Delegates
- razor
- razor
- Razor
- Razor
- Razor
- Razor 一知半解
- Razor语法
- Razor 模板
- Razor表达式
- Razor语法
- Razor语法
- Razor表达式
- MVC Razor
- Razor语法
- Razor表达式
- Razor 语法
- 新打开acitivyt时,EditText焦点自动带出软键盘问题解决方法总结
- INCREMENTAL(增量链接)
- 本人所接触的(用到的或者仅仅是了解的)技术和工具
- UVA 10375 (13.11.07)
- TCP传输大文件问题总结
- 高级 Razor : Templated Razor Delegate
- DP 入门题COJ 1788
- #pragma comment
- 计算机的计量单位KMGTPEZY
- C++中的宏定义
- js弹框alert出现乱码
- c#中用默认浏览器打开页面
- Python中文问题
- IOS Table中Cell的重用reuse机制分析