asp.net – RenderBody和RenderSection之间的区别
发布时间:2020-05-23 15:00:29 所属栏目:asp.Net 来源:互联网
导读:在MVC / Razor语法中,我试图理解为什么我们需要@RenderBody。 例如(从example开始的代码) html head meta charset=utf-8 / titleMy WebSite/title style #container { width: 700px; }
|
在MVC / Razor语法中,我试图理解为什么我们需要@RenderBody。 例如(从example开始的代码) <html>
<head>
<meta charset="utf-8" />
<title>My WebSite</title>
<style>
#container { width: 700px; }
#left { float: left; width: 150px; }
#content { padding: 0 210px 0 160px; }
#right { float: right; width: 200px; }
.clear { clear: both; }
</style>
</head>
<body>
<div id="container">
<div id="left">
@RenderSection("left",required:false)
</div>
<div id="content">
@RenderBody()
</div>
<div id="right">
@RenderSection("right",required:false)
</div>
<div class="clear"></div>
</div>
</body>
</html>
@{
Layout = "~/_3ColLayout.cshtml";
}
<h1>Main Content</h1>
@section left {
<h1>Left Content</h1>
}
@section right {
<h1>Right Content</h1>
}
为什么我不能简单地使用@RenderSection的一切,像这样: <div id="content">
@RenderSection("Body",required:true)
</div>
@section Body{
<h1>Body Content</h1>
}
解决方法只是因为方便。渲染身体是你最有可能做的事情,所以它有一个专门的功能。让你不要为身体声明一个@section,并提供一个更容易调用的功能。(编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-web-api – OAuthBearerAuthenticationMiddleware
- 为什么在使用当前同步上下文启动任务时,不设置ASP.NET Http
- asp.net-mvc – JSON,ASP.NET MVC – MaxJsonLength异常
- asp.net-mvc – 使用令牌认证访问Web Api的MVC .NET cookie
- asp.net – 使用区域时,“路由表中没有路由匹配提供的值”
- asp.net – Html.BeginForm()类型的扩展名
- asp.net – 通过CSS重置HTML元素的高度
- asp.net-mvc – AllowAnonymous不能使用自定义Authorizatio
- asp.net中使用repeater和PageDataSource搭配实现分页代码
- asp.net – 如何使用jQuery ajax避免快速结果的“闪烁”进度
