Socolov Vladislav
Socolov Vladislav

Reputation: 43

How deny access direct URL to my partial views?

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

Thank's!

Upvotes: 3

Views: 1894

Answers (2)

Persian.
Persian.

Reputation: 1035

add [ChildActionOnly] .. like this :

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

Upvotes: 3

Andiih
Andiih

Reputation: 12423

As Andras says, this would only happen if you have a controller action to return them. I can see that you might have those in place in which case you should add the attribute (filter them) as [ChildActionOnly]

Upvotes: 1

Related Questions