" />
开发者

Best practices for building links in MVC

If I do not want to do this in my View Markup,

<%=Html.RouteLink("Listings", "Listings", new {m开发者_JS百科arket = "Austin", state = "Texas", pagenumber = 3 })%>

what would be the best approach to creating links in MVC 2? I have a HTML helper to build a custom link but all it is doing is acting as a wrapper around RouteLink (or ActionLink). I would want something more elegant and one that has a shorter syntax. If I build my links in a controller, how do I push it into the view? Via ViewData? (hope not). Or would it be part of the ViewModel?


I like using T4MVC better than MVC Futures ActionLink helpers. You line would look like this:

<%:Html.ActionLink("Listings", MVC.Listings.Index("Austing", "Texas", 3)) %>

http://mvccontrib.codeplex.com/wikipage?title=T4MVC


Long term, I think the Html.ActionLink which you see in the MVC Futures library is the way to fly:

<%= Html.ActionLink<ListingsController>(x => x.Listings("Austin", "Texas", 3)) %>

Using your HtmlHelpers, even if they are just wrappers around the current magic-string based functionality as it at least reduces your frontage to magic strings and provides a single point to change.

I wouldn't get involved in building links on the back-end if I could help it in an effort to make syntactical sugar.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜