开发者

How to generate a path/url from a Route within a Model class?

This is similar to the SO question here..

How to generate a path/url from a Route in the Routes table?

..only this time I'd like to be able to build a url within one of my Model (parti开发者_运维知识库al) classes.

I'm defining a new property that will contain the text to be rendered within an rss feed, and want to insert urls (within anchor tags) in this text.

I found the UrlHelper.GenerateUrl method, but get unstuck once I get beyond passing in the appropriate RouteName, ActionName and ControllerName.


Generating urls in the model is actually a bad idea. I would recommend you generating the url in the controller and pass it to the model as parameter if necessary or use a HTML helper in the view which will do the job.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜