为什么要使用ASP.NET MVC局部视图(的.ascx) [英] Why use ASP.NET MVC partial View (.ascx)
问题描述
为题说。什么是为什么我添加视图控制器的一个方法,我应该选择复选框的原因,并情景创建一个局部视图(的.ascx)?
As the topic says. What are the reasons and scenarios why I am adding a view for a controller method, that I should select the checkbox "Create a partial view (.ascx)?
推荐答案
由于@Brandon指出您使用PartialViews可重用性和可读性。
As @Brandon points out you use PartialViews for reusability and readability.
举个例子,你有交往的一个IQueryable列表中的场景。
Take for example a scenario where you have an IQueryable list of contacts.
您会对它通过列表和渲染项的局部视图循环的局部视图。
You would have a partial view which looped through the list and a partial view which rendered the items.
当你这样做的,你可以写code,使该循环局部视图来决定哪些局部视图应该呈现的接触,如果有比单一的方式重新present数据更多。
When you do it that way, you could write code that enabled the looping partial view to decide which partial view should render the contact if there are more than a single way to represent the data.
如果你再放置在共享fodler他们可以在整个应用程序中使用的部分景色。
If you then place those partial views in a shared fodler they can be used throughout the entire application.
此外,您还可以使用AJAX / jQuery的呼叫到控制器的动作。然后,该行动将返回,然后可以在屏幕上显示一个PartialView。使您的网站看起来非常光滑,当你不刷新整个页面。
Also, you can use an AJAX/jQuery call to a controllers action. That action would then return a PartialView which can then be displayed on screen. Makes your site look very slick when you don't refresh the entire page.
这篇关于为什么要使用ASP.NET MVC局部视图(的.ascx)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!