Ok, so today I’ve finally updated my local copy of the MVC source code (which I’m doing through my preferred SVN client) and lo-and-behold: new stuff to talk about in the MVC futures source code! Today we’re going to talk about the ActionLink control.
As you might expect (from the name), this is a really simple control which extends the base MvcControl. Currently, it exposes the following properties:
- ActionName: lets you pass the action name that should be used for rendering the link;
- ControllerName: lets you set the name of the controller. Used for influencing the generated url;
- RouteName: as you’ve probably guessed, you can use this to generate a link by using its name;
- Values: lets you pass a dictionary for setting the route’s dictionary values;
- Text: used for setting the text that is generated for the link.
If you’re used to using the Html.ActionLink helper, then there really shouldn’t be anything new in here. Anyway, here’s an example of how you can use this new control in your page:
Text="Go to about" />
Unlike the other controls, the name property isn’t really used internally to get any info from the view data dictionary. You’re probably wondering how you can fill the Values property. Nothing better than a quick example…the next snippet creates a link to the Index action and sets its id property (I’m using the default routes you get when you create a new MVC app):
<mvc:actionlink runat="server" ActionName="Index" Text="Go to about" name="message">
<Values id="1" />
This ends up generating the following HTML:
<a name="message" href="/MvcRTM/home/Index/1">Go to about</a>
If you had more parameters, you could simply add them as attributes to the Value element. And that’s it for today. Stay tuned for more on the MVC framework.