views:

16

answers:

1

I have a custom handler I've written that executes a custom action based on a parameter, for example:

/action/option1

would execute the action handler with option1. I can have any number of options for the parameter...

however this action is a custom handler, NOT an mvc controller, because I'm returning a plain text (possibly moving to a json response in the future) not an html page.

how can I route urls of that format to run through the custom handler, passing the option as a parameter? I though of using the iis7 url rewrite, which sounds ideal but I didn't know if there was a better option...

thanks!

+2  A: 

Even if you're just returning text you should still do it via controllers and actions. Your action should just return a ContentResult instead of a ViewResult. That way you still get the built in routing and you can just change it later to return a JsonResult if needs be.

Dave
neat! I didn't know there was such a thing. so are httphandlers discouraged in mvc?
Josh
I think it's generally encouraged to use ActionResults wherever possible. There's a whole set of different classes that derive from it, it's not just views, text and json either.
Dave
thanks this was a big help!
Josh