开发者

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

开发者 https://www.devze.com 2023-01-26 21:20 出处:网络
This is similar to the SO question here.. How to generate a path/url from a Route in the Routes table?

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

精彩评论

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

关注公众号