Route Building

Param

The Param method adds a key-value pair to the current route values collection

@( Html.BuildActionLink("Login", "Login", "Account").
        Param("returnUrl", Request.Url.PathAndQuery))

Params

The Params method will accept either an anonymous object or an IDictionary<string, object>

@( Html.BuildActionLink("Login", "Login", "Account").
        Params(new {returnUrl = Request.Url.PathAndQuery}))

ReSharper Support

Build.Mvc supports the JetBrains ReSharper AspMvc annotations

Route Building Samples

A link to a Controller Action

@(Html.BuildActionLink("Add event to your calendar:").
        ControllerRoute("Services", "iCal").
        Param("id", Model.DinnerID))

A link to the payment details page in the Accounting area

@(Html.BuildActionLink("View payment details").
        AreaRoute("Accounting", "Payments", "PaymentDetail").
        Param("id", Model.PaymentId))

A link that goes to the default action on the ActionLink controller.

@( Html.BuildActionLink("Test ActionLinks").
            ControllerName("ActionLink"))

A link that goes to the Page2 action on the ActionLink controller

@( Html.BuildActionLink("Test ActionLinks").
        ControllerName("ActionLink").
        ActionName("Page2"))

A link that goes to the default action on the Payments controller in the Accounting Area

@( Html.BuildActionLink("Test ActionLinks").
        AreaName("Accounting").
        ControllerName("Payments"))

Last edited Dec 23, 2011 at 4:16 PM by grcodemonkey, version 9

Comments

No comments yet.