Home >Backend Development >C++ >How to Create Action Links to Controllers Outside Their Folders in ASP.NET MVC?

How to Create Action Links to Controllers Outside Their Folders in ASP.NET MVC?

Linda Hamilton
Linda HamiltonOriginal
2025-01-22 13:02:10792browse

How to Create Action Links to Controllers Outside Their Folders in ASP.NET MVC?

Creating Action Links in MVC

When working with a controller in a location outside of its folder, it's necessary to create links to the desired methods. For the Html.ActionLink method, the following parameters are required:

Signatures

ASP.NET MVC1:

public static string ActionLink(this HtmlHelper htmlHelper, 
string linkText,
string controllerName,
string actionName,
object values, 
object htmlAttributes)

ASP.NET MVC2:

public static string ActionLink(this HtmlHelper htmlHelper, 
string linkText,
string actionName,
string controllerName,
object values, 
object htmlAttributes)

ASP.NET MVC3 :

public static string ActionLink(this HtmlHelper htmlHelper, 
string linkText,
string actionName,
string controllerName,
object values, 
object htmlAttributes)

Example

Consider the following scenario:

public class ItemController:Controller
{
    public ActionResult Login(int id)
    {
        return View("Hi", id);
    }
}

To create a link to the Login method from a page outside the Item folder, use the following code:

The above is the detailed content of How to Create Action Links to Controllers Outside Their Folders in ASP.NET MVC?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn