剃刀视图与部分视图
Visual Studio 如何确定哪个是视图还是部分视图?另一个问题是;有没有办法将我的视图转换为部分视图?
how does visual studio determine which is a view vs a partial view? Another question would be; is there a way to convert my views into partial views?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Razor 中,视图和部分视图之间没有 WebForms 中的区别(.aspx 与 .ascx)。在 Razor 中,所有视图都是模板。这些模板可以有一个布局:
在本例中它们是视图。如果没有指定布局,它们可以被视为部分视图。布局通常在
~/Views/_ViewStart.cshtml
文件中定义。也就是说,如果您从控制器操作中返回 PartialView(); 而不是
return View();
,则不会应用此布局。我建议您阅读以下博客文章 关于 Razor 视图和布局。
In Razor there is no distinction between views and partial views as there is in WebForms (.aspx vs .ascx). In Razor all views are templates. Those templates could have a Layout:
In this case they are views. If there is no layout specified they could be considered as partial views. The Layout is usually defined in the
~/Views/_ViewStart.cshtml
file.This being said if from your controller action you
return PartialView();
instead ofreturn View();
this layout will not be applied.I would recommend you reading the following blog post about Razor views and layouts.
Visual Studio 无法确定哪个是视图、哪个是部分视图。你做。您告诉 MVC 渲染部分视图,它会渲染您提供的任何内容。
Visual Studio doesn't determine which is a view and which is a partial view. You do. You tell MVC to render a partial view, and it renders whatever you give it.