如何使用盒子构建网站
我正在设计一个页面,需要在主要内容的左侧和右侧都有框(部分视图)。这些盒子将包含额外的信息,就像 SO 上一样。我想对页面进行分组,因此某些页面将有一些框,而另一组的页面将有其他框。
但我怀疑如何在 MVC.NET 中最好地实现这一点。
我看到两个选项:
1)在每个页面上我都包含我需要的部分控件。
2)创建子母版页,我可以在其中分配页面,并且可以控制应显示哪些部分视图。
还有其他更聪明或更容易实施的方法吗?
I am designing a page which needs to have boxes (partial views) on both the left and the right side of the main content. The boxes will contain extra information just like on SO. I would like to group the pages, so certain pages will have some boxes, and pages of another group will have other boxes.
I am though in doubt how this is best accomplished in MVC.NET.
I see two options:
1) On every page I include the partial controls I need.
2) Create sub-master pages where I can assign a page to, and which can control which partial views should be shown.
Are there any other ways of doing this, which would be smarter or easier to implement?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SO 页面上的框与页面内容严格相关,因此我将创建一个包含 3 个内容占位符的母版页 (Site.Master):
如果您有一系列具有相同框的功能,我会为以下内容创建母版页:它们并放置类似 (Controller.Master) 的内容:
使用 Controller.Master 的操作会在
RightContentSubcontent
中放置其他框。如果框确实独立于当前页面,您还可以使用 RenderAction:
RenderAction 创建新请求来渲染页面的一部分。它可能更容易使用,但我会使用 RenderAction 来表示不与主视图共享任何信息的框(例如,如果您想显示“时钟”框、“最新下载”框或“登录”框)。
Boxes on SO pages are strictly related to content of the page, so I would create one master page with 3 content placeholders (Site.Master):
If you had some range of functionalities, that have the same boxes, I would create master page for them and place something like (Controller.Master):
Actions using Controller.Master would place additional boxes in
RightContentSubcontent
.If boxes are really independent of current page, you can also use
RenderAction
:RenderAction
creates new request to render part of the page. It may be easier to use, but I would useRenderAction
for boxes, that do not share any information with the main view (for example if you wanted to display "Clock" box, "Latest downloads" box or "Login" box).将内容放入页面侧边栏的方法有很多种...
There are many ways to put content into sidebars on pages...