Terrence
Terrence

Reputation: 43

asp.net.MVC How to produce RESTful url like this: /mycontroller/myaction/24

Could someone show me the syntax of an Html.ActionLink that will produce a hyperlink that looks like this:

<a h ref="/mycontroller/myaction/67">mylinktext</a>

thanks. Terrence

Upvotes: 0

Views: 177

Answers (2)

Mattias Jakobsson
Mattias Jakobsson

Reputation: 8237

It depends more on how you set up your routes. But if you only have the default route and myaction takes one parameter named id it can look like this:

<%=Html.ActionLink("mylinktext", "myaction", "mycontroller", new { id = 67 }, null) %>

Or, if you want and have mvc features or mvc2, it can look like this:

<%=Html.ActionLink<mycontroller>(x => x.myaction(67), "mylinktext")%>

Upvotes: 1

Kieron
Kieron

Reputation: 27127

To generate a link, use the HtmlHelper and the Action extension...

<%= Html.ActionLink ("mycontroller", "myaction", new { id = 67 }) %>

Upvotes: 1

Related Questions