开发者

asp.net mvc routing to a custom handler instead of controller?

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 pla开发者_StackOverflow中文版in 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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜