<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="MvcApp2.Views.Home.Index" %>
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
<h2><%= Html.Encode(ViewData["Message"]) %></h2>
<p>
To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
</p>
</asp:Content>
除非知道輸出的是一段Html編碼的字符串,可以直接輸出字符串。因為當字符串中帶有空格或者<,這種可能引起瀏覽器曲解,就要加上Html.Encode進行Html編碼的轉換,以防出現一些不必要的錯誤。