Specific application of attribute [Childactiononly]

Asked

Viewed 264 times

4

I saw from the ASP.NET MVC documentation that the use of the attribute [ChildActionOnly] prevents the method from being called directly via GET, only through a specific view. Frankly, I don’t understand. Someone can clarify?

Example of use:

[ChildActionOnly]
public ActionResult Resultado()

1 answer

4


I removed from the documentation this passage here:

Any method marked with ChildActionOnlyAttribute might be called only through Action or RenderAction HTML Extensions methods.

That is, if you have content that must be part of a main view, normally PartialViews.

In what scenarios this could be useful?

For example when creating a template where some parts of your site are divided into PartialViews, like _top.cshtml, _bottom.cshtml with actions Top() and Bottom() it may be interesting to avoid them being displayed directly in the browser from the url: site.com.br/home/top

Browser other questions tagged

You are not signed in. Login or sign up in order to post.