How to prevent direct URL access to my partial views?

I have some partial views in my controller. The problem is that users can visualize my partial views if they are placed in the URL: (www.mydomain.com/mycontroller/mypartialview). How can I deny direct access ... and only allow partial views from the base view?

Thank you in!

+3
source share
2 answers

add [ChildActionOnly] .. like this:

[ChildActionOnly]
        public PartialViewResult List(Model model)
        {...
            return PartialView(model);
        }
+3
source

As Andras says, this will only happen if you have a controller action to return them. I see that you can have those on which you should add an attribute (filter them) as [ChildActionOnly]

+1

All Articles