Monday, April 11, 2011

does an MVC Action have to return an actionResult?

Can a so called action in my controller just be a regular function that returns anything I want or does the return of an ActionResult declare whether its an "action" or not?

I was wondering if i could call functions in my ActionLink in the "actionname" that didn't return actionresults.

thx

From stackoverflow
  • All public methods of a controller are actions by default, regardless of return type. So, yes, you can call them. Use [NonActionAttribute] to override this default.

    Dacrocky : Yeah my question probably didn't make sense all that much, but this is what i wanted to know. thanks
  • Yes, all actions should return an ActionResult. The MVC engine only know to handle an ActionResult (or a derivative).

    I don't understand what you mean with "call functions in my ActionLink that don't return ActionResults". Even if you don't want to return any meaning, you still have to return an ActionResult.

    What is it you want to accomplish?

    Craig Stuntz : Should, I agree. Must, that's not true. Try it!

0 comments:

Post a Comment