什么是 MVC 子操作? [英] What is an MVC child action?

查看:21
本文介绍了什么是 MVC 子操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 MVC(基础书籍)中阅读了有关子操作的内容,但我真的不知道它是什么?

I read about child actions in MVC (fundamental book), but I don't really know what it is?

有人可以解释一下这些方法吗?

Could some one please explain these methods?

推荐答案

Phil Haack 在 这篇博文.基本上,子动作是一个控制器动作,您可以使用 Html.Action 助手从视图中调用它:

Phil Haack explains it nicely in this blog post. Basically a child action is a controller action that you could invoke from the view using the Html.Action helper:

@Html.Action("SomeActionName", "SomeController")

此操作将在视图中的指定位置执行并呈现其输出.与 Partial 的区别在于 Partial 只包含指定的标记,除了主操作之外没有其他操作执行.

This action will then execute and render its output at the specified location in the view. The difference with a Partial is that a partial only includes the specified markup, there's no other action executing than the main action.

因此,您基本上拥有接收请求并呈现视图的主要操作,但是在此视图中,您可以呈现多个子操作,这些子操作将经历其独立的 MVC 生命周期并最终呈现输出.而这一切都将在单个 HTTP 请求的上下文中发生.

So you basically have the main action which received the request and rendered a view, but from within this view you could render multiple child actions which will go through their independent MVC lifecycle and eventually render the output. And all this will happen in the context of a single HTTP request.

子操作对于创建可以嵌入到您的视图中并经历其独立 MVC 生命周期的整个可重用小部件非常有用.

Child actions are useful for creating entire reusable widgets which could be embedded into your views and which go through their independent MVC lifecycle.

这篇关于什么是 MVC 子操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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