如何布局MVC3剃刀页? [英] How to layout a page with MVC3 Razor?

查看:116
本文介绍了如何布局MVC3剃刀页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读有关布局,章节,观点和局部的观点,但我真的不知道如何处理布局像这样的例子:


  • 顶栏:会像栏
    Facebook的有在上面。我将包含
    的认证信息和
    一般选项和菜单。


  • 导航条:将包含
    关于你在哪里,以及信息
    你能去哪里。又一个搜索
    框。


  • 正文:实际想要的信息。


  • 边栏:将包含有关
    关于什么是在信息
    身体。


  • 页脚:版权,授权和事
    这样的。


正文的将是一个查看,的补充工具栏的将是一个节的页脚的将在布局静态的HTML ,但是......这将是最常见的酒吧和导航的?

最常见栏的是不与任何关系,所以我把它作为布局一个局部视图,但我不能这样做,因为它是<$ C内$ C>&LT;身体GT; 无论如何,所以当我打电话 @RenderBody(),它应该被渲染。用的导航的,它在某种程度上与身体有关,但我想它单独作为对自己的运行的外部控制和显示根据在URL中的信息。

我应该如何处理这个?

更新,请阅读:这个问题的不是关于CSS和HTML,它不是关于如何布局这一点,但如何使用剃刀工具来做到这一点,它是关于剃刀 RenderBody PartialView

当我从控制器返回一个结果,我想回到正是被标记的图片作为身体和边栏作为一个部分,我想,以避免重复最上面一栏code。有没有一种方法来创建一个ChildView,从ParentView继承,这从布局,在某种程度上,当我回到视图(ChildView),屏幕会自动建立?


解决方案

检查出的 MVC3音乐商店教程

这教程的最后一部分介绍了如何设计布局,包括使用Html.RenderAction()方法的部分看法。另请参阅Html.RenderSection()方法。

I've been reading about layouts, sections, views and partial views, but I don't really know how to approach a layout like this example:

  • Top bar: would be like the bar that Facebook have on top. I would contain the authentication information and general options and menus.

  • Navigation bar: would contain information about where are you, and where can you go. Also a "search" box.

  • Body: The actual wanted information.

  • Side bar: would contain relevant information about what is in the body.

  • Footer: copyright, licence and things like that.

Body would be a "View", Sidebar would be a "Section", Footer would be static HTML in the "Layout", but... what would be Top bar and Navigation?

Top bar is not related with anything, so I would put it as a "Partial View" in the "Layout", but I cannot do that because it has to be inside the <body> anyway, so when I call @RenderBody(), it should be rendered. Same thing with Navigation, it's somehow related with the body, but I'd like to separate it as an external control that runs on his own and show information depending on the information in the URL.

How should I approach this?

UPDATE, please read: The question is not about CSS and HTML, it's not about how to layout this, but how to use the Razor tools to do it, it's about Razor RenderBody and PartialView.

When I return a result from my controller, I want to return just what is marked in the picture as "body", and "side bar" as a section, I'd like to avoid repeat the top bar code. Is there a way to create a "ChildView", that inherits from "ParentView", and this from "Layout", in a way that when I return "View("ChildView") the screen is built automatically?

解决方案

Check out the MVC3 Music Store Tutorial

The last part of that tutorial describes how design the layout to include partial views using the Html.RenderAction() method. Also see the Html.RenderSection() method.

这篇关于如何布局MVC3剃刀页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆