Is it possible to create a Partial View, which has a controller, which can be called from another view using
Html.RenderAction(...)
BUT without that same controller being accessible via a URL?
So for example
public class ArticlesController : Controller
{
public ActionResult HomeList()
...
}
Gives a list of latest articles for the bottom of my web pages.
So I call this from
_Layout.cshtml
However I dont want someone coming to
mysite.com/Articles/HomeList
and seeing the same list for various reasons (security, SEO, etc.)
Thanks
Edit:
I ended up using my own attribute class, thanks to Russ's help:
public class ChildActionOnly404Attribute : FilterAttribute, IAuthorizationFilter
{
void IAuthorizationFilter.OnAuthorization(AuthorizationContext filterContext)
{
if (!filterContext.IsChildAction)
{
throw new HttpException(404, "");
}
}
}
apply the ChildActionOnlyAttribute
to the action. This means that it
I've found it to be useful for cross-cutting concerns like menus and navigation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With