Is it possible to utilize internal methods on controllers to reduce duplication?
-
25-09-2019 - |
Question
in a partial view I have the following:
<%Html.RenderAction(MVC.User.GetComments(Model.UserGroupName)); %>
can I render a Controller
's PartialViewResult
in a View
without going through routing so I can pass arguments directly from the model so that the arguments I'm passing to the controller never get sent to the user or seen by the user?
Currently the method I'm showing at the top throws an exception because no overload is public. I've got it marked as internal so that a user can not access it, only the rendering engine was my intent.
Solution
Slap a [ChildActionOnly] attribute on any action method if you want that method to be callable only by RenderAction() rather than the outside world. Or - if you have a whole controller of such methods - slap the attribute on the controller itself.