我什么时候应该在asp.net mvc中使用局部视图?

问题描述:

我已经查看过示例ASP.NET MVC书呆子晚餐应用程序...但是仍然无法理解我应该在何时何地进行局部查看?

I ve gone through sample asp.net mvc nerd dinner application... But still cant understand the point where and when should i go for partial views?

  • 它类似于webformw中的用户控件吗?

注意: 可以看到部分视图正在运行...任何示例...

Note: It would be helpful to see a partial view in action... Any sample...

任何您要使用的都不止一次.例如,在此SO页面上,您会在右侧看到相关帖子的列表.那是在多个页面上,所以为什么要多次创建它.您可以将数据传递到部分视图以根据特定条件对其进行自定义.

Anything you would use more than once. For instance on this page for SO, you see the listing of related posts over to the right. That is on multiple page, so why create it multiple times. You can pass data to the partial view to customize it based on certain criteria.

在某些情况下,例如登录,我不喜欢它,我希望将用户带到登录页面.但是,这种情况经常使用.

I do not like it for certain things like login, where I would rather take the user to a login page. However that scenario is used often.