在 MVC 中使用 ChildActionOnly [英] Using ChildActionOnly in MVC

查看:15
本文介绍了在 MVC 中使用 ChildActionOnly的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您何时会使用属性 ChildActionOnly?什么是 ChildAction,在什么情况下您希望使用此属性限制操作?

When would you use the attribute ChildActionOnly? What is a ChildAction and in what circumstance would you want restrict an action using this attribute?

推荐答案

ChildActionOnly 属性确保动作方法只能作为子方法调用从视图中.一个动作方法不需要有这个属性作为子动作使用,但是我们倾向于使用此属性来防止操作方法因用户而被调用要求.定义了一个动作方法后,我们需要创建动作时将呈现的内容调用.子操作通常与部分视图相关联,尽管这不是强制性的.

The ChildActionOnly attribute ensures that an action method can be called only as a child method from within a view. An action method doesn’t need to have this attribute to be used as a child action, but we tend to use this attribute to prevent the action methods from being invoked as a result of a user request. Having defined an action method, we need to create what will be rendered when the action is invoked. Child actions are typically associated with partial views, although this is not compulsory.

  1. [ChildActionOnly] 允许通过视图中的代码限制访问

  1. [ChildActionOnly] allowing restricted access via code in View

特定页面 URL 的状态信息实现.示例:支付页面 URL(只需支付一次)razor 语法允许有条件地调用特定操作

State Information implementation for specific page URL. Example: Payment Page URL (paying only once) razor syntax allows to call specific actions conditional

这篇关于在 MVC 中使用 ChildActionOnly的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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