局部视图和布局有什么区别? [英] What is the difference between Partial View and Layout?

查看:86
本文介绍了局部视图和布局有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中同时使用了局部视图和布局概念,我无法区分.但我的感觉是两者都在做同样的工作.谁能说说 Partial View 和 Layout 的简要概念以及与示例的区别?

I had used both the Partial View and also the Layout Concept in my Project i cannot able to differentiate. But what i am feeling is both doing the same work. Can anyone tell the brief idea about the Partial View and Layout and difference with example?

推荐答案

除了 Josh 的回答,我的 aweeeesomeee 绘画技巧还想给你画一张图,说明一切..

In addition to Josh's answer, my aweeeesomeee paint skills would like to draw you a picture that should explain all..

承认吧……你很敬畏……

Admit it... you're in awe...

您会看到页眉和页脚...您甚至可以在那里看到部分视图.

You see the header and footer... you could even have partial view's there too.

举一个不同的例子来说明为什么要使用每个组件(布局/视图/部分视图),假设您拥有一个总共有 100 个页面的网站,并且假设您要更新网站的设计,你打算怎么做?

To give you a different example of why you use each component (layout / view / partial view), imagine that you own a website that has 100 pages in total, and lets say you want to update the design of your website, how are you going to do it?

单独更新每个页面会让我发疯,因为您不断地为每个页面复制代码,只是为了更新您的设计.

Updating each page individually would drive me insane, because your replicating your code constantly for every single page, just to update your design.

这是布局视图可以帮助您解决的问题,您可以使用布局视图为所有页面创建模板.

This is what the Layout view helps you solve, you use the Layout view to create a template for all of your pages.

使用我们现有的 100 页网站场景,每个页面都将具有独特的内容,视图允许我们在使用 Layout 中的模板的同时显示这些内容.

Using our existing scenario of 100 page website, each page is going to have content that is unique, the View allows us to display this content whilst using our template from the Layout.

现在让我们假设我们允许访问者在我们的页面上发表评论,每个评论必须看起来一致,并且行为与我们网站上的所有其他评论完全相同......要实现这一点,您将使用 部分视图 它将作为您在网站上收到的评论的模板.

Now lets imagine that we allow our visitors to comment on our pages, each comment must look consistent, and behave exactly the same as all the other comments throughout our website... To achieve this, you would use a Partial View which would act as a template for the comments that you receive on your website.

这样做的好处是你不必到处重复你的代码,你只需要创建一个Partial View来呈现任何评论.

The benefits of doing this is that you don't have to repeat your code everywhere, you only have to create one Partial View to render any comment.

这篇关于局部视图和布局有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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