Asp.net MVC razor语法参考
Razor语法的快捷参考http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx/
只是copy下来便于查阅!
I gave a presentation to another team at Microsoft yesterday on ASP.NET MVC and the Razor view engine and someone asked if there was a reference for the Razor syntax.
It turns out, there is a pretty good guide about Razor available, but it’s focused on covering the basics of web programming using Razor and inline pages and not just the Razor syntax.
So I thought it might be handy to write up a a really concise quick reference about the Razor syntax.
Syntax/Sample | Razor | Web Forms Equivalent (or remarks) |
---|---|---|
Code Block |
|
|
Expression (Html Encoded) |
|
|
Expression (Unencoded) |
|
|
Combining Text and markup |
|
|
Mixing code and Plain text |
|
|
Using block |
|
|
Mixing code and plain text (alternate) |
|
Same as above |
Email Addresses |
|
Razor recognizes basic email format and is smart enough not to treat the @ as a code delimiter |
Explicit Expression |
|
In this case, we need to be explicit about the expression by using parentheses. |
Escaping the @ sign |
|
@@ renders a single @ in the response. |
Server side Comment |
|
|
Calling generic method |
|
Use parentheses to be explicit about what the expression is. |
Creating a Razor Delegate |
|
Generates a Func<T, HelperResult> that you can call from within Razor. See this blog post for more details.
|
Mixing expressions and text |
|
|
NEW IN RAZOR v2.0/ASP.NET MVC 4 | ||
Conditional attributes |
|
When className = null
When
When
|
Conditional attributes with other literal values |
|
When className = null
Notice the leading space in front of
|
Conditional data-* attributes.
data-* attributes are always rendered. |
|
When xpos = null or ""
When
|
Boolean attributes |
|
When isChecked = true
|
URL Resolution with tilde |
|
When the app is at /
When running in a virtual application named
|
Notice in the “mixing expressions and text” example that Razor is smart enough to know that the ending period is a literal text punctuation and not meant to indicate that it’s trying to call a method or property of the expression.
Let me know if there are other examples you think should be placed in this guide. I hope you find this helpful.
UPDATE 12/30/2012:I’ve added a few new examples to the table of new additions to Razor v2/ASP.NET MVC 4 syntax. Razor got a lot better in that release!
Also, if you want to know more, consider buying the Progamming ASP.NET MVC 4 book. Full disclosure, I'm one of the authors, but the other three authors are way better.
转载于:https://www.cnblogs.com/dereklovecc/p/3539940.html
Asp.net MVC razor语法参考相关推荐
- MVC Razor 语法(转)
http://blog.sina.com.cn/s/blog_580e98300100yvz4.html 原文地址:MVC Razor 语法(转)作者:panzhaowen_jacki 语法名称 Ra ...
- ASP.NET MVC Razor视图引擎
本篇文章我们一起来讨论ASP.NET MVC框架中的Razor视图引擎.主要包含以下内容: Razor简介 Razor语法 Razor如何呈现页面 布局页(Layout) Razor简介 Razor是 ...
- asp.net mvc 包含了一个 html 的助手类在哪里,c# - 在App_Code中使用@HTML的ASP.NET MVC Razor Helper - 堆栈内存溢出...
我尝试在cshtml文件中的App_Code中创建一个Helper. // Using's are needed to ensure helpers function correctly. @usin ...
- Asp.net MVC3 Razor语法小记
1.在MVC View中使用 三元运算符的方式:@(bool?"":"") 2.在@{}中输出一行:@:<html> 3.Radio默认选中: @H ...
- mvc5控制器修改html,ASP.NET MVC Razor:如何在控制器动作中呈现Razor局部视图的HTML...
我看到有人想知道如何为另一个控制器执行此操作. 就我而言,我的所有电子邮件模板都位于Views / Email文件夹中,但是您可以对其进行修改以传递与之关联了视图的控制器. public static ...
- ASP.NET MVC 自定义Razor视图WorkContext
概述 1.在ASP.NET MVC项目开发的过程中,我们经常需要在cshtml的视图层输出一些公用信息 比如:页面Title.服务器日期时间.页面关键字.关键字描述.系统版本号.资源版本号等 2.普通 ...
- 如何在 ASP.NET MVC 中集成 AngularJS
介绍 当涉及到计算机软件的开发时,我想运用所有的最新技术.例如,前端使用最新的 JavaScript 技术,服务器端使用最新的基于 REST 的 Web API 服务.另外,还有最新的数据库技术.最新 ...
- netcore 编译 html dll,ASP.NET Core Razor 视图预编译、动态编译
0x01 前言 ASP.NET Core在默认发布情况下,会启动预编译将试图编译成xx.Views.dll,也许在视图中打算修改一处很细小的地方我们需要再重新编译视图进行发布.下面我将从 ASP.NE ...
- ASP.NET MVC 简单的分页思想与实现
首先我们通过VS创建一个空的基于Razor视图引擎的ASP.NET MVC3 Web应用程序,命名为JohnConnor.Web 对创建过程或Razor不太了解的看官,请移步 ASP.NET MVC ...
最新文章
- 去除文本框点击的背影
- 教你从零开始使用wordpress做为后台生成小程序(小白版教程)
- spring jmx_JMX和Spring –第2部分
- pip加速+百度镜像|清华镜像
- Redis 缓存实战——缓存、数据库一致性问题分析与解决方案
- python 倒排索引(Inverted Index)
- 宠物火葬行业调研报告 - 市场现状分析与发展前景预测(2021-2027年)
- 【java笔记】网络编程概述
- 你用java的swing可以做出这么炫的mp3播放器吗?
- 2021 年最佳开源软件榜单出炉
- 英特尔的新方向:称王集成计算设备领域
- 设计测试用例需要注意的点
- 搜集各种稀奇古怪的编码
- 辣子鸡-辣子鸡家常做法
- com.thoughtworks.xstream.converters.reflection.ReflectionConverter,用XSTream将xml转换为Java对象
- 一个通过SOAP web service驱动ssh/telnet执行命令的小平台
- django qq邮箱发送验证码
- 80核处理器_最受欢迎的处理器 酷睿i5-9400F果然霸榜了
- HDU 4508 湫湫系列故事――减肥记I
- MATLAB fprintf 函数输出希腊字母/特殊字符