我正在使用ASP.NET MVC 2编写的Web应用程序。我正在为我的视图创建模板,并且我正在使用asp:ContentPlaceHolder
以便我可以粘贴在内容中加入模板。
以下是主模板的示例:
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
<asp:ContentPlaceHolder ID="MetaContent" runat="server" />
<asp:ContentPlaceHolder ID="StyleContent" runat="server" />
</head>
<body>
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
<asp:ContentPlaceHolder ID="ScriptContent" runat="server" />
</body>
</html>
现在,如果只有MainContent
替换为<h1>Hello World</h1>
并且所有其他占位符都留空,则html输出如下所示:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Home</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
浏览器似乎并不介意,但我确实如此。我希望我的输出看起来像这样:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Home</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
如果占位符的内容留空,有没有办法阻止输出新行?