Question :
I saw through the ASP.NET MVC documentation that using the [ChildActionOnly]
attribute prevents the method from being called directly via GET, only through a specific view. Frankly, I did not get it. Can anyone clarify?
Example usage:
[ChildActionOnly]
public ActionResult Resultado()
Answer :
I removed the documentation from this section here:
Any method marked with
ChildActionOnlyAttribute
can be
called only throughAction
orRenderAction
HTML extensions
methods.
That is, if you have content that must be part of a main View, usually PartialViews
.
In what scenarios could this be useful?
For example, when you build a template where parts of your site are split into PartialViews
, such as _top.cshtml, _bottom.cshtml with actions Top()
and Bottom()
, it might be of interest to prevent them from appearing directly in the browser. from url: site.com.br/home/top