开发者

Generating a URL from a static class

I have a static utility class shared among several controllers. What's the easiest way of generating the url of an action method? Do i really have 开发者_开发问答to pass an instance of the UrlHelper of a controller to generate a url?


Yes, you have to. Url generation does depend on routing system, application virtual path and many other things that UrlHelper takes care of - and there's no need to write that logic by yourself.


One way to do this is to create a shared Controller base class that is inherited from by all of your controllers.

All of the utility functions would then be instance methods, and can get at everything that any instantiated MVC controller can get at.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜