MVC: How Do I Prevent Exposing a Public Method on a Controller?

March 31, 2008 8:30 PM

The purists will say that you shouldn't have any public methods on a controller that aren't meant to be exposed via a view or redirect to another action. Assuming that you, like I, have encountered a situation where you need/want to do this, however, here is what you do:

[NonAction]
public void Foo(){ /* Implementation... */ }

The System.Web.Mvc.NonAction attribute will prevent your public method from being accessed via any routes.

Tags: ,
Categories: MVC
Actions: E-mail | Permalink | Comments (0) RSS Feed for this post's comments.

Add Comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading




Troy Goode

Troy Goode
Microsoft Certified Professional Developer
AddThis Feed Button

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in  anyway.

© Copyright 2008

Colophon

Powered by:
BlogEngine.NET 1.4
Template:
Designs by Darren
Header Font:
Stamper
Syntax Highlighting:
WLW Code Snippet Plugin