Html. Actionlink Method
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...
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.
10 Answers
I think what you want is this:
Must Read
ASP.NET MVC1
Html.ActionLink(article.Title,
"Login", // <-- Controller Name.
"Item", // <-- ActionMethod
new { id = article.ArticleID }, // <-- Route arguments.
null // <-- htmlArguments .. which are none. You need this value
// otherwise you call the WRONG method ...
// (refer to comments, below).
)
This uses the following method ActionLink signature:
public static string ActionLink(this HtmlHelper htmlHelper,
string linkText,
string controllerName,
string actionName,
object values,
object htmlAttributes)