本文共 1454 字,大约阅读时间需要 4 分钟。
本页面仅作测试页面处理
public class Program{ public static void Main(string[] args) {} }
123456Hello Web Pages
The time is @DateTime.Now
@{...}
包围@
开头var
关键字声明变量.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/