MVC3 Partial View needs a controller, but can I make it non-public?

Is it possible to create a Partial View that has a controller that can be called from another view using

Html.RenderAction (...)

BUT without the same controller being accessible via URL?

So for example

public class ArticlesController : Controller { public ActionResult HomeList() ... } 

Lists recent articles for the bottom of my web pages.

Therefore i call it from

_Layout.cshtml

However, I do not want anyone to come to

mysite.com/Articles/HomeList

and seeing the same list for various reasons (security, SEO, etc.)

thanks

Edit:

As a result, I used my own attribute class, thanks to the help of Rus:

 public class ChildActionOnly404Attribute : FilterAttribute, IAuthorizationFilter { void IAuthorizationFilter.OnAuthorization(AuthorizationContext filterContext) { if (!filterContext.IsChildAction) { throw new HttpException(404, ""); } } } 
+4
source share
1 answer

apply ChildActionOnlyAttribute to the action. That means he

  • can only be called inside the application, and not directly through route matching
  • can only be called using the extension methods Action or RenderAction HTMLHelper

I found this to be useful for cross-cutting tasks like menus and navigation.

+9
source

All Articles