Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I use the same action name for both the GET and POST versions of my methods. I'd like to call the GET method even during a postback based on a condition. For example I added the following selector attribute:

public class NotFormAttribute : ActionMethodSelectorAttribute {
    public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) {
        return controllerContext.HttpContext.Request.QueryString["IsForm"] == null;
    }
}

Now I have to go through and apply this to every POST action method in my application. This seems slightly tedious. I'd tried to register it as a global filter but it didn't allow it (as it doesn't implement IActionFilter).

Does anyone know how I can do this? Thanks

share|improve this question
    
I think a global action filter is what you need. –  tweray Jul 7 '14 at 14:58
    
Thanks but the trouble with a global action filter is that it stops any action from being executed. I still need the GET method to execute. –  nfplee Jul 7 '14 at 15:05
    
I think stackoverflow.com/questions/9497023/… is currently your only hope. –  haim770 Jul 7 '14 at 15:09
    
Thanks I came across that post myself but the solution doesn't really work for my scenario as it searches for an action and then does nothing if it's not applicable instead of falling back to the GET method. –  nfplee Jul 7 '14 at 15:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.