开发者

Best way to pass navigation / link information from controller to view?

In an ASP.NET MVC app I have a page with a dynamically generated list of links to different pages in the app. What is the best way for the controller to pass the link information to the view?

I want to keep the view as simple as possible and I'm assuming it's wrong to generate URLs in the controller (too UI specific, makes unit testing harder etc.) so for each link I currently pass an action string, a controller string and a RouteVal开发者_开发问答ueDictionary object. I then use URL.Action() in the view to create the link. Is this the best way to go or is there a neater way that doesn't involve three separate objects per link?


We pass just a RouteValueDictionary, instead of passing that + 2 strings. The RVD is allowed to have controller and action members. You can pass null for the action argument and the action member of the RVD will be used instead.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜