开发者

ASP.NET MVC - generating html for a View in a Controller

I have a MySmartAnchor method that outputs a Html link. Depending on an object that I pass to MySmartAnchor it will set specific css class and tooltip.

I feel like this is too much logic to put in a View. I don't want to add this method to HtmlHelper methods because it addresses a specific scenario. So I'm thinking of putting this logic i开发者_如何学编程nside of a controller and calling it from a View like so @Model.MySmartAnchor(someObject)

Am I on the right track? Should this be done in a View, put inside of a helper method, or controller? I also thought about having a partial but it seems to me it is overkill for a link.


Seems like good candidate for creating razor helper. If that's only single view specific helper, you should create that into same view that uses it. Else, create helper into App_Code, for using it across multiple views. Referenced article by ScottGu covers that as well.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜