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
Release: 2025-01-22 13:02:10
Original
822 people have browsed it

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)
Copy after login

ASP.NET MVC2:

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

ASP.NET MVC3 :

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

Example

Consider the following scenario:

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

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template