Let's say I have a class
public class ItemController:Controller
{
public ActionResult Login(int id)
{
return View("Hi", id);
}
}
On a page that is not located at the Item folder, where ItemController
resides, I want to create a link to the Login
method. So which Html.ActionLink
method I should use and what parameters should I pass?
Specifically, I am looking for the replacement of the method
Html.ActionLink(article.Title,
new { controller = "Articles", action = "Details",
id = article.ArticleID })
that has been retired in the recent ASP.NET MVC incarnation.
Best Answer
I think what you want is this:
ASP.NET MVC1
This uses the following method ActionLink signature:
ASP.NET MVC2
two arguments have been switched around
This uses the following method ActionLink signature:
ASP.NET MVC3+
arguments are in the same order as MVC2, however the id value is no longer required:
This avoids hard-coding any routing logic into the link.
This will give you the following html output, assuming:
article.Title = "Title"
article.ArticleID = 5
. .