[英]ASP.Net Using @Html.ActionLink() for Navbar buttons
我目前正在使用Visual Studio MVC。 由於MVC有助於自動為某些功能創建代碼。 我試圖了解這段代碼的含義。 我了解前兩個參數,但不了解第三個參數。
-----> @ Html.ActionLink(“顯示的文本”,“控制器中的方法名稱”,“第三???”)
我的控制器代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MP.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return View();
}
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
}
}
下面是我不明白的代碼:
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
第三個參數是控制器的名稱。 在您的情況下,您有一個名為HomeController
的控制器,因此第三個參數是"Home"
(按照慣例,您省略了“ Controller”后綴)。
如果使用HomeController
的方法生成了@Html.ActionLink()
方法的頁面,則可以省略第3個參數,例如,在About
頁面中,可以使用
<li>@Html.ActionLink("Home", "Index")</li>
但是,如果Index()
方法位於(例如) ProductController
,則它必須是
<li>@Html.ActionLink("Home", "Index", "Product")</li>
您可以在智能感知系統中看到-
此處明確提及- string controllerName
。
此外,此幫助程序可以提供10種類型的擴展程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.