博客
关于我
ASP.NET MVC模式——WebPages
阅读量:469 次
发布时间:2019-03-06

本文共 1454 字,大约阅读时间需要 4 分钟。

本页面仅作测试页面处理
public class Program{  public static void Main(string[] args)  {}        }

 

WebPages

示例

123456     

Hello Web Pages

The time is @DateTime.Now

Razor

  • 一种对网页添加服务器代码的标记语法
  • 支持C#和Visual Basic

语法规则

  1. @{...}包围
  2. 行内表达式以@开头
  3. 代码以分号结尾
  4. 通过var关键字声明变量
  5. 字符串用引号包围
  6. C#对大小写敏感
  7. C#扩展名.cshtml

示例

12345678910111213
@{ var myMessage = "Hello World"; }

The value of myMessage is: @myMessage

@{var greeting = "Welcome to our site!";var weekDay = DateTime.Now.DayOfWeek;var greetingMessage = greeting + " Today is: " + weekDay;}

The greeting is: @greetingMessage

布局

内容块

通过Web Pages,可以使用@RenderPage()从不同文件导入。

内容块能够输入到网页中任意位置,可包含文本标记代码

示例

12345678@RenderPage("header.cshtml")

Hello Web Pages

This is a paragraph

@RenderPage("footer.cshtml")

使用布局页面

布局页类似于普通网页。但在引用内容页的位置调用。

每个内容页面必须以Layout开头。

123456789@{Layout="Layout.cshtml";}

Welcome to W3Schools

Lorem ipsum dolor sit amet, consectetur adipisicing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laborisnisi ut aliquip ex ea commodo consequat.

在ASP.NET中,名称以下划线开头的文件无法通过 web 来浏览。

如果您希望禁止用户查看内容块或布局文件,请对文件重新命名:

_header.cshtml
_footer.cshtml
_Layout.cshtml

隐藏敏感信息

在ASP.NET中,隐藏敏感信息(数据库密码、电邮密码等)的常用方法是把这些信息保存在名为 “_AppStart” 的独立文件中。

1234567@{WebMail.SmtpServer = "mailserver.example.com";WebMail.EnableSsl = true;WebMail.UserName = "username@example.com";WebMail.Password = "your-password";WebMail.From = "your-name-here@example.com";}

 

转载地址:http://mlwfz.baihongyu.com/

你可能感兴趣的文章
MySql中怎样使用case-when实现判断查询结果返回
查看>>
Mysql中怎样使用update更新某列的数据减去指定值
查看>>
Mysql中怎样设置指定ip远程访问连接
查看>>
mysql中数据表的基本操作很难嘛,由这个实验来带你从头走一遍
查看>>
Mysql中文乱码问题完美解决方案
查看>>
mysql中的 +号 和 CONCAT(str1,str2,...)
查看>>
Mysql中的 IFNULL 函数的详解
查看>>
mysql中的collate关键字是什么意思?
查看>>
MySql中的concat()相关函数
查看>>
mysql中的concat函数,concat_ws函数,concat_group函数之间的区别
查看>>
MySQL中的count函数
查看>>
MySQL中的DB、DBMS、SQL
查看>>
MySQL中的DECIMAL类型:MYSQL_TYPE_DECIMAL与MYSQL_TYPE_NEWDECIMAL详解
查看>>
MySQL中的GROUP_CONCAT()函数详解与实战应用
查看>>
MySQL中的IO问题分析与优化
查看>>
MySQL中的ON DUPLICATE KEY UPDATE详解与应用
查看>>
mysql中的rbs,SharePoint RBS:即使启用了RBS,内容数据库也在不断增长
查看>>
mysql中的undo log、redo log 、binlog大致概要
查看>>
Mysql中的using
查看>>
MySQL中的关键字深入比较:UNION vs UNION ALL
查看>>